Welcome to DOGZILLA-Lite 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/DOGZILLA_Lite_class/4.Open Source CV/B.Geometric_Transformations/02_Image_Cropping.ipynb
ximport cv2img = cv2.imread('yahboom.jpg', 1)dst = img[500:700,300:500] #这里选取矩形区域X:300-500 Y:500-700 Here we select a rectangular area X: 300-500 Y: 500-700#cv2.imshow('image',dst)#cv2.waitKey(0)xxxxxxxxxx#bgr8转jpeg格式 bgr8 to jpeg formatimport enumimport cv2def bgr8_to_jpeg(value, quality=75): return bytes(cv2.imencode('.jpg', value)[1])xxxxxxxxxximport ipywidgets.widgets as widgetsimage_widget1 = widgets.Image(format='jpg', )image_widget2 = widgets.Image(format='jpg', )# display the container in this cell's outputdisplay(image_widget1)display(image_widget2)img1 = cv2.imread('yahboom.jpg',1)image_widget1.value = bgr8_to_jpeg(img1) #原始图像 The original imageimage_widget2.value = bgr8_to_jpeg(dst) #剪切的图像 cropped image