Welcome to Raspberry Pi 5 repository
2. Read and display Open Source CV images
2. Read and display Open Source CV images
Reading of images:
img = cv2.imread('yahboom.jpg', 0) The first parameter is the path of the image, and the second parameter is how to read the image.
cv2.IMREAD_UNCHANGED: Keep the original format unchanged, -1;
cv2.IMREAD_GRAYSCALE: Read the image in grayscale mode, which can be represented by 0;
cv2.IMREAD_COLOR:, read in a color picture, which can be represented by 1; default value;
cv2.IMREAD_UNCHANGED: Read in an image and include its alpha channel, which can be represented by 2.
Image display
The code was run on jupyterlab
x#bgr8 to jpeg formatimport enumimport cv2def bgr8_to_jpeg(value, quality=75):return bytes(cv2.imencode('.jpg', value)[1])
xxxxxxxxxx#The image component in jupyterLab displays the read imageimport ipywidgets.widgets as widgetsimage_widget = widgets.Image(format='jpg', width=800, height=800)display(image_widget)image_widget.value = bgr8_to_jpeg(img)
