Function method: cv2.imwrite('yahboom1.jpg', img).
The first parameter is the saved filename and the second parameter is the saved image.
Below we demonstrate the method of image writing. First, read an image yahboom.jpg, and then write yahboom1.jpg.
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:
xxxxxxxxxx
IP:9999 // Example: 192.168.1.11:9999
Code path:/root/Dofbot/4.opencv/1.OpenCV_basic/02_write_pic.ipynb
import cv2
# 1 Reading of files 2 Encapsulation format analysis 3 Data decoding 4 Data loading
img = cv2.imread('yahboom.jpg', 1)
# cv2.imshow('yahboom, img) #See the explanation below
cv2.imwrite('yahboom1.jpg', img) # 1 name 2 dat
The cv2.imshow('yahboom, img) function in jupyLab cannot be executed. If you need to use this sentence to display the read image, you need to execute the python file through the command, command: python3 XX.py
xxxxxxxxxx
#bgr8 to jpeg format
import enum
import cv2
def bgr8_to_jpeg(value, quality=75):
return bytes(cv2.imencode('.jpg', value)[1])
xxxxxxxxxx
import ipywidgets.widgets as widgets
image_widget = widgets.Image(format='jpg', width=320, height=240)
display(image_widget)
img = cv2.imread('yahboom1.jpg',1)
image_widget.value = bgr8_to_jpeg(img)
When the code block finishes running, you can see that the yahboom.jpg image is written to yahboom1.jpg.