Opencv-python use

Source: Internet
Author: User

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

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.