Welcome to Raspbot V2 repository
当製品の日本語版マニュアル資料は、こちらからご取得ください。
2. Image cutting
2. Image cutting
2.1. Image cutting
Image cutting first reads the image, and then obtains the pixel area in the array. In the following code, select the shape area X: 300-500 Y: 500-700. Note that the image size is 800*800, so the selected area should not exceed this resolution.
2.2. Actual effect display
Code path:
/home/pi/project_demo/06.Open_source_cv_fundamentals_course/B.Geometric_Transformations/02_Image_Cropping.ipynb
xxxxxxxxxximport cv2img = cv2.imread('yahboom.jpg', 1)
dst = img[500:700,300:500] #Here we select a rectangular area X: 300-500 Y: 500-700
#cv2.imshow('image',dst)
#cv2.waitKey(0)x#bgr8 to jpeg format bgr8 to jpeg formatimport enumimport cv2
def bgr8_to_jpeg(value, quality=75): return bytes(cv2.imencode('.jpg', value)[1]) ``` ```python import ipywidgets.widgets as widgets image_widget1 = widgets.Image(format='jpg', ) image_widget2 = widgets.Image(format='jpg', ) # display the container in this cell's output display(image_widget1) display(image_widget2) img1 = cv2.imread('yahboom.jpg',1) image_widget1.value = bgr8_to_jpeg(img1) #Original image The original image image_widget2.value = bgr8_to_jpeg(dst) #Cropped image cropped image ``` 