Opencv-python Study Note 1: Simple picture processing

Source: Internet
Author: User
Tags ord

first, 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

123456789101112131415161718 # -*- coding: utf-8 -*-"""@xiaowuyi:http://www.cnblogs.com/xiaowuyi"""import cv2img=cv2.imread(‘1.jpg‘,cv2.IMREAD_COLOR)# 读入彩色图片cv2.imshow(‘image‘,img)#建立image窗口显示图片k=cv2.waitKey(0)#无限期等待输入if k==27:#如果输入ESC退出    cv2.destroyAllWindows()    elif k==ord(‘s‘):#如果输入s,保存    cv2.imwrite(‘test.png‘,img)    print "OK!"    cv2.destroyAllWindows()

Show Results:

3. Display and save black and white pictures

123456789101112131415161718 # -*- coding: utf-8 -*-"""@xiaowuyi:http://www.cnblogs.com/xiaowuyi"""import cv2img=cv2.imread(‘1.jpg‘,cv2.IMREAD_GRAYSCALE)# 读入彩色图片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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.