DEV Community

arpitmandliya
arpitmandliya

Posted on

OpenCV Python tutorial

OpenCV is a massive open source library for computer vision, and picture processing. OpenCV supports a huge array of programming languages such as Python, C++, Java, etc. It can process pictures and videos to identify items, faces and can be very useful in a lot of scenarios.
For example: Auto tag feature used by facebook. When you upload a picture to facebook, it automatically detects the person and suggests you tag the person.

OpenCV stands for open source computer vision library. It is widely used for image detection. It was first introduced by intel and was written in C/C++. It is generally used in Python for computer visions.

Install OpenCV on Windows and linux

You need to install python first on your machine.
You can check python version using:

Python --version
Enter fullscreen mode Exit fullscreen mode

You can use pip to install opencv. pip is standard package manager for Python and it will help you install packages not available in Python Standard library.
To install OpenCV, just to command line and type:

pip install opencv-python #Python 2
pip3 install opencv-python #Python 3
Enter fullscreen mode Exit fullscreen mode

If you want to check if OpenCV is correctly installed, then you can use the following command.

>>> Python
>>> import cv2
>>> print(cv2.__version__)
Enter fullscreen mode Exit fullscreen mode

In case you are using anaconda then you can use following command"

>> conda install -c menpo opencv3
Enter fullscreen mode Exit fullscreen mode

In case, you are getting modulenotfounderror, then you can use CV2 modulenotfounderror: no module named cv2 to resolve the issue.

OpenCV Python tutorial

This OpenCV tutorial will help you to understand the basic Image-processing with a lot of examples.

It includes following tutorials:

OpenCV introduction: It provides quick introduction to openCV python library.
CV2 imread: cv2 imread method is used to read image from path.
CV2 imwrite: cv2 imwrite method is used to save image to the disk.
CV2 imshow: cv2 imshow is used to display image in the window.
CV2 resize: cv2 resize is used to resize an image.
CV2 videocapture: cv2 videocapature is used to read and start live streaming.
CV2 threshold: CV2 threshold is used to separate an object form the background in the image.
CV2 canny: Cv2 canny method is used to detect edges in an image.
CV2 findcontours: cv2 findcontours method is used find boundaries of an image.
CV2 gaussianblur: CV2 gaussianblur is used to blur an image.
CV2 cvtcolor: CV2 cvtcolor is used to convert color of an image from one color space to another.

Top comments (0)