Read in image
The read-in image uses Cv2.imread ().
Read mode:
Cv2. Imread_color: Read a pair of color images, the transparency of the image is ignored, this is the default parameter
Cv2. Imread_grayscale: Reading into images in grayscale mode
Cv2. Imread_unchanged: Reads a pair of images and includes an alpha channel of the image
# -*-coding:utf-8-*- Import Cv2 Import = cv2.imread ('test.jpg', 0)
The read path is wrong and there is no hint. Can only get a none
Display image
Use Cv2.imshow () to display the image.
The window is automatically resized to the image size.
The first parameter is the name of the window, followed by our image.
You can create multiple windows with different names.
Cv2.waitkey () is a keyboard binding function.
Its time scale is the millisecond level.
The function waits for a certain number of milliseconds to see if there is a keyboard input.
If any input returns the ASCII value of the key, continue running.
If there is no input, return-1.
If the setting parameter is 0, the key will wait indefinitely.
Cv2.destroyallwindows ()
You can delete the created window (you can specify the window name)
# -*-coding:utf-8-*- Import Cv2 Import = cv2.imread ('test.jpg', 0) cv2.imshow ('image ' , IMG) cv2.waitkey (0) cv2.destroyallwindows ()
You can also create a window before loading the image.
Cv2.namedwindow ('image', Cv2. Window_normal) cv2.imshow ('image', img) cv2.waitkey (0) cv2.destroyallwindows ()
Save Image
Cv2.imwrite (' name ', object)
Precautions:
Cv2.waitkey () when used, if it is a 64-bit system, change to Cv2.waitkey () & 0xFF
Python OpenCV reading and displaying images