Opencv_python use
First, the GUI features in OpenCV:
1. Read in the Image:
The Cv2.imread () function reads into the image. The parameters are:
(1) The path to this picture.
(2) Tell the function how to read the image:
Cv2. Imread_color: Reads a pair of color images. However, the transparency of the image is ignored and can be expressed in 1.
Cv2. Imread_grayscale: Reads the image in grayscale mode, which can be expressed in 0.
Cv2. Imread_unchanged: Reading an image and including the alpha channel of the image, I haven't tried out how to say it.
1 Import NumPy as NP 2 Import Cv2 3 img=cv2.imread ('F:\python\opencv\pic\kongfu.jpg', 0)
View Code
2. Display Image:
Cv2.imshow () displays the image. The first parameter is the name of the window, followed by the obtained image parameter.
3. Save the Image:
Use the function Cv2.imwrite () to save an image. The first parameter is a file name, followed by the image you want to save.
Summary code:
1 #The following program will load a grayscale graph, display pictures, press the ' s ' key to save and exit, or press ESC to exit without saving2 ImportNumPy as NP3 ImportCv24Img=cv2.imread ('F:\python\opencv\pic\kongfu.jpg', 0)5Cv2.imshow ('Kung Fu Panda', IMG)6k=cv2.waitkey (0)7 ifK==27:8 cv2.destoryallwindows ()9 elifK==ord ('s'):TenCv2.imwrite ('F:\python\opencv\pic\kongfu.png', IMG) OneCv2.destroyallwindows ()
View Code
Opencv-python use