1. Read pictures
cv2.imread('abc.jpg', 0)
arg1: image name; arg2: way of reading, cv2.IMREAD_COLOR: value 1, read in color image, cv2.IMREAD_GRAYSCALE: value 0, read in grayscale mode; cv2.IMREAD_UNCHANGED: value -1, with alpha channel read
2. Display pictures
cv2.imshow('Image', img)
arg1: window name, it needs to be unique when there are multiple windows; arg2: the displayed picture
3. Keyboard binding function
key = cv2.waitKey(nnn)
arg1: The number of milliseconds to wait, during which time if there is any key press, the program can listen to and process it. If there is no key input, the program continues to execute. If it is 0, it will wait indefinitely.
When used to display video, you can control the speed of the video (set the waiting time for each frame)
Returns the ASCII value of the key
4. Close the window
cv2.destroyAllWindows(): closes all created windows.
cv2.destroyWindow(xxx): close a specific window, the window name is passed in by parameter
5. Save the picture
cv2.imwrite('abc.jpg', im)
arg1: save file name, arg2: image to be saved
----- sample coding -----
import cv2
img = cv2.imread('messi.jpg', 0)
cv2.imshow('Image', img)
k = cv2.waitKey(0)
if k == 27: # wait for ESC to exit
cv2.destroyAllWindows()
elif k == ord('s'): #wait for 's' key to save and exit
cv2.imwrite('Messigray.png', img)
cv2.destroyAllWindows()
-- End --