Welcome to NUWA-HP60C Depth Camera repository
7.Picture cutting
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.
Start Docker
After entering the Raspberry Pi 5 desktop, open a terminal and run the following command to start the container corresponding to Dofbot:
xxxxxxxxxx./Docker_Ros.sh
Access Jupyter Lab within Docker:
xxxxxxxxxxIP:9999 // Example: 192.168.1.11:9999
Code path:/root/Dofbot/4.opencv/2.Transform/02_cut_pic.ipynb
ximport cv2img = cv2.imread('yahboom.jpg', 1)dst = img[500:700,300:500] #Select the rectangular area X: 300-500 Y: 500-700#cv2.imshow('image',dst)
#cv2.waitKey(0)The following will display two compressed image comparison displays in the jupyterLab control.
xxxxxxxxxx#bgr8 to jpeg formatimport enumimport cv2def bgr8_to_jpeg(value, quality=75): return bytes(cv2.imencode('.jpg', value)[1])Compare the before and after images below:
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) #Original imageimage_widget2.value = bgr8_to_jpeg(dst) #Cut imageAfter the program is finished running, you can see that some parts have been cut out.
