reprint Please specify: @ Xiao Wu Yi Http://www.cnblogs.com/xiaowuyi qq Group: 64770604first, the main function
1, cv2.imread (): Read into the picture, a total of two parameters, the first parameter is to read the picture file name, the second parameter is how to read the picture, including Cv2. Imread_color: Read in a color picture;Cv2. Imread_grayscale: Read into the image in grayscale mode;Cv2. Imread_unchanged: Read in a picture and include its Alpha channel.
2,cv2.imshow (): Create a window to display pictures, a total of two parameters, the first parameter represents the window name, you can create more than one window, but each window cannot have duplicate names; The second parameter is a read-in picture.
3,Cv2.waitkey (): Keyboard binding function, a total of one parameter, indicating the number of milliseconds to wait, will wait for a specific few milliseconds, see if the keyboard has input, the return value is an ASCII value. If its argument is 0, it represents an indefinite wait for keyboard input.
4,cv2.destroyallwindows (): Delete all created Windows.
5,cv2.destroywindows (): Deletes the specified window.
6,cv2.imwrite (): Save the picture, a total of two parameters, the first to save the file name, the second for reading into the picture.
Second, examples
1, take the following picture as an example
2. Display and save color pictures
#-*-Coding:utf-8-*-"" "@xiaowuyi: Http://www.cnblogs.com/xiaowuyi" "" Import cv2img=cv2.imread (' 1.jpg ', Cv2. Imread_color) # read in color picture cv2.imshow (' Image ', img) #建立image窗口显示图片k =cv2.waitkey (0) #无限期等待输入if k==27: #如果输入ESC退出 Cv2.destroyallwindows () elif K==ord (' s '): #如果输入s, save cv2.imwrite (' test.png ', img) print "ok!" Cv2.destroyallwindows ()
Show Results:
3. Display and save black and white pictures
#-*-Coding:utf-8-*-"" "@xiaowuyi: Http://www.cnblogs.com/xiaowuyi" "" Import cv2img=cv2.imread (' 1.jpg ', Cv2. Imread_grayscale) # read in color picture cv2.imshow (' Image ', img) #建立image窗口显示图片k =cv2.waitkey (0) #无限期等待输入if k==27: #如果输入ESC退出 Cv2.destroyallwindows () elif K==ord (' s '): cv2.imwrite (' test.png ', img) print "ok!" Cv2.destroyallwindows ()
Show Results:
Opencv-python Study Note 1: Simple picture processing