Picture Cut
If we want to cut the picture. First, we need to read the image, and then get the pixel area in the array.
In the following code, the area range we selected is X: 300-500 Y: 500-700,
Because the image size is 800*800, the area we choose should not exceed this resolution.
Code:
import cv2 img = cv2.imread('yahboom.jpg', 1) dst = img[500:700,300:500] # Area range we selected, X:300-500 Y:500-700 #cv2.imshow('image',dst) #cv2.waitKey(0)
|
After running the following program, two images will be displayed in the jupyterLab control interface, that is original image and the cut image.
#bgr8 to jpeg format import enum import cv2 def bgr8_to_jpeg(value, quality=75): return bytes(cv2.imencode('.jpg', value)[1])
|
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) # Orginial picture image_widget2.value = bgr8_to_jpeg(dst) # Cut picture
|

[Orginial picture] [Cut picture]