Computer Vision: Computer vision is an interdisciplinary field that deals with the automation of what human vision can do. Human vision is used to receive and analyze visual information (known as sight). Similarly, computer vision automates a computer to receive, process, analyze and understand digital images or videos.
There are many computer vision libraries available. OpenCV is one of the most popularly used libraries. Here we will discuss how we can use OpenCV with Python 3.X versions.
What is OpenCV?
OpenCV (Open Source Computer Vision Library) is released under a BSD license and hence it’s free for both academic and commercial use. It has C++, Python and Java interfaces and supports Windows, Linux, Mac OS, iOS and Android. OpenCV was designed for computational efficiency and with a strong focus on real-time applications. Written in optimized C/C++, the library can take advantage of multi-core processing. Enabled with OpenCL, it can take advantage of the hardware acceleration of the underlying heterogeneous compute platform.
According to OpenCV.org, OpenCV has a user community of more than 47 thousand people and downloads exceeding 14 million. It is used for a wide range of applications, ranging from image analysis to advanced robotics.
OpenCV with Python 3.X
Installing OpenCV 3 with Python 3.X
Install Python on your computer following the instructions that are given on its official website. Python exists in two versions Python 2.X and Python 3.X. Python 2.X being the predecessor of Python 3.X version, it may come to its end sooner or later. Thus, consider installing Python 3.X.
After installing it, open your command prompt or terminal and run the command: python
If it is successfully installed, the Python interpreter would get opened:
After installing Python, consider installing the libraries: OpenCV, Numpy and Matplotlib.
Numpy: It is a Python package for performing sophisticated scientific calculations.
Matplotlib: It is a Python plotting package for data visualization.
As of now OpenCV does not have required files for Python 3.X. Therefore, download appropriate wheel (based on the version of Python installed) package from https://www.lfd.uci.edu/~gohlke/pythonlibs/. Download the wheel package and install using pip command.
pip install opencv_python-3.X.version-X-win32.whl
Similarly, download Numpy and Matplotlib and install them using the pip commands.
On Linux or Mac
It is much easier to install OpenCV and other related libraries in Linux based operating systems and OS X. In most of the Linux based operating systems has both Python 2.X and Python 3.X preinstalled. If it is not installed, install Python 3.X and pip3 (apt-get install python3-pip).
Now, using pip3 install OpenCV, Numpy and Matplotlib.
pip3 install numpy pip3 install matplotlib pip3 install python3-OpenCV
Testing for Right Installation
Open the Python interpreter using Python command and import the libraries installed as shown below.
While importing the packages as shown above, if you encounter no errors, the installation is successful. If not try doing it again.
Here we have looked into what is computer vision, OpenCV, and its facts. We have installed OpenCV with Python together with two other useful libraries: Numpy and Matplotlib.
What’s for the Next
In the next section, I will show you how to write our first OpenCV with Python program. In it, I will introduce you to some of the basic functions, how to import libraries into the program, capture, and display video: OpenCV with Python – Loading Video Source