Enter Python-opencv:cv2.imread (), Cv2.imshow (), Cv2.imwrite () __python

Source: Internet
Author: User

Why use PYTHON-OPENCV

Although Python is powerful and has its own image-processing library PIL, it's still a lot weaker than OpenCV. Like many open source software OpenCV also provides a perfect Python interface, very easy to invoke. OpenCV's stable version is 2.4.8, the latest version is 3.0, contains more than 2,500 algorithms and functions, almost any mature algorithm can be thought of can be called by the OpenCV function to achieve, super convenient. One, need tools

This machine uses the Python 2.7.10 to debug the code to pass, the study needs to have certain code reading ability, the study only introduces the function method:

Python, as a highly efficient and concise literal language, is perfect for us to solve everyday problems. And it's easy to learn, beginners can start a few hours basic. Coupled with the numpy and matplotlib wings, Python's ability to analyze data is no inferior to that of MATLAB. Python is also known as the glue language, and there are a lot of software that provides the Python interface. Especially in Linux, you can use Python to make different software a workflow, to play each software's own maximum advantage to complete a complex task. For example, we can use MySQL to store data, use R to analyze data, use Matplotlib to display data, use OpenGL for 3D modeling, and use QT to build a beautiful GUI. And python can combine them together to build a powerful workflow. second, the introduction of the small test

1, the image reads: Cv2.imread ()

Use the function Cv2.imread () to read the image. This image should be in the working path of this program, or provide a full path to the function, and the second parameter is to tell the function how to read the picture.

Cv2. Imread_color: Read a pair of color images. The transparency of the image will be ignored,
This is the default parameter.
Cv2. Imread_grayscale: Reading images in grayscale mode

#-*-Coding:utf-8-*-
"" "
Created on Mon Sep modified 19:51:58 2015

@author: Eddy_zheng
" ""
import cv2
  
    #import NumPy as NP

# grayscale pattern load a pair
of graphics img = cv2.imread (' lena.jpg ', 0) #没有女神lena的, can be saved by itself @_@

  

PS: Call OpenCV, even if the path of the image is wrong, OpenCV will not remind you, but when you use life
The result of the print IMG is none.

2, display Image cv2.imshow ()

Use the function 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, as long as you like, but you have to give them different names.

Cv2.imshow (' Image ', img)

cv2.waitkey (0) "" "
Cv2.waitkey () is a keyboard binding function. It needs to be pointed out that its time scale is the
second level. The function waits for a specific number of milliseconds to see if there is a keyboard input. Within a specific millisecond, if you
press any key, this function returns the ASCII value of the key, and the program will continue to run. If there is no
keyboard input, the return value is-1, and if we set the parameter of this function to 0, it will
wait for the keyboard input indefinitely. It can also be used to detect whether a particular key is being pressed, such as whether a button A is
being pressed, which we will discuss later. "" "
cv2.destroyallwindows ()" ""
cv2.destroyallwindows () can easily delete any window we create. If
you want to delete a specific window you can use Cv2.destroywindow () and enter the name of the window you want to delete in parentheses
.
"""

3, Save the Image Cv2.imwrite ()

Cv2.imwrite (' Lena.png ', IMG)

Lena

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.