opencv

How to install OpenCV Ubuntu

How to install OpenCV Ubuntu

OpenCV is an open source computer vision library available under the BSD license. So it is free for academic and commercial use. The library is written in C and C++. It runs on Linux, Windows, Mac OS, iOS, and Android. It has C, C++, Java, MATLAB and Python interfaces. OpenCV has more than 2,500 optimized algorithms for real-time computer vision.

The aim of the OpenCV community is to create a computer vision infrastructure that allows developers to create complex applications with relative ease. The library is designed for computational efficiency for real-time applications. So it has a wide array of uses in face recognition, gesture recognition, medical imaging, human-computer interaction, motion tracking, security monitoring, robotics, camera controls and more.

Besides the computer vision components, OpenCV also has support for general-purpose machine learning. Machine learning (ML) is an important technology for computer vision problems. So the ML library makes OpenCV more attractive to computer vision developers.

Computer Vision and OpenCV

Computer vision was created with the goal to replicate human vision capabilities. It uses algorithms to transform captured images into data and makes it easier to comprehend real-world vision problems.

In the case of human vision, our eyes work as input devices. Then our brains divide the image streams into multiple channels for processing. Besides visual data, the human brain also takes into account other sensory data and uses it to understand spacial depth. It gives human brains the ability to understand three-dimensional space.

When we collect data through cameras we get a two-dimensional view of the world. Computer vision algorithms take the two-dimensional images and use mathematical properties to figure out the three-dimensional representations. It is an extremely difficult problem to solve.

Also, computer vision often uses other contextual information to overcome the limitations of two-dimensional images. It takes into account information like color, brightness or contrast. For example, if an object recognition algorithm is looking for a wood table, it can safely eliminate any non-wood related colors from the input images. Also, computer vision algorithms eliminate noise in the input data.

The OpenCV library is designed to make the implementation of computer vision algorithms easier. It handles computational complexity so developers can concentrate on high-level tasks.

History of OpenCV

In 1999, OpenCV started at Intel as an initiative to advance CPU-Intensive applications. Gary Bradski who was working at Intel at the time noticed that students at MIT Media Lab were sharing libraries to get a head start in computer vision applications. This inspired the idea for building a computer vision infrastructure that can be used easily.

From Intel, the OpenCV project moved to Willow Garage, a robotics research lab and technology incubator based in Menlo Park, California. Currently, the OpenCV open source project is maintained by Itseez, a customized computer vision software development and consultancy company.

OpenCV version 1.0 was released in 2006. The next major version 2.0.0 came in 2009. The current major version 3.0.0 was released in 2015. The most recent version to-date is OpenCV 3.3.0.

Using OpenCV

The library has gained popularity among scientists and academics. It is often used as a teaching tool for computer vision. But OpenCV is robust enough to support real-world problems.

You can use OpenCV for non-commercial and commercial products. It is used by industry giants like Google, Yahoo, Microsoft, Intel, IBM, Sony, Honda, and Toyota. Research institutes in leading universities like MIT, CMU, Stanford, and Cambridge provide support for the library. The OpenCV Yahoo Group has 50,000 members worldwide.

Installing OpenCV

In order to demonstrate the installation of OpenCV I will use Ubuntu 17.10 and will perform the installation into a fresh docker image in order to ensure there are no conflicting packages for the OpenCV dev environment.  Here is my command line for docker setup:

docker pull ubuntu
docker run -it 00fd29ccc6f1 bash
apt-get update

Ok great, now you have a fresh environment, let's install some required dependencies to make the environment usable.

apt-get install wget cmake g++ unzip vim

Next we need the source code of OpenCV. You can get the source code from the website here, and ensure that you download the latest version.  Unpack it and then create a build directory for the CMake system and enter the directory:

wget https://github.com/opencv/opencv/archive/3.3.1.zip
cd opencv-3.3.1
mkdir build
cd build

Next we can build the library and install it into the system path in the docker image.  If you are not using docker, you will to decide on your build prefix, but using a dedicated docker image makes all this very simple as show below:

cmake…
make
make install

To verify the build and installation was successful lets write a trivial C++ test program that includes a OpenCV library and then run it.  Here is a sample code you can use to test your install:

#include "opencv2/core/core.hpp"
#include
int main()

cv::Point2f p(4, 5);
std::cout << "Point output: " << p << std::endl;
return 0;

You can build and run it like so:

root@6d6b443afced:~/src# g++ test.cpp -o test
root@6d6b443afced:~/src# ./test
Point output: [4, 5]

Congrats its working, the job is done.

Next Steps

OpenCV Face Recognition

References:

  • https://opencv.org/
  • https://opencv.org/about.html
  • https://docs.opencv.org/3.3.1/d1/dfb/intro.html
  • https://en.wikipedia.org/wiki/OpenCV
Gry Najlepsze emulatory konsoli do gier dla systemu Linux
Najlepsze emulatory konsoli do gier dla systemu Linux
W tym artykule wymienimy popularne oprogramowanie do emulacji konsoli do gier dostępne dla systemu Linux. Emulacja to warstwa kompatybilności oprogram...
Gry Najlepsze dystrybucje Linuksa do gier w 2021 r
Najlepsze dystrybucje Linuksa do gier w 2021 r
System operacyjny Linux przeszedł długą drogę od pierwotnego, prostego, serwerowego wyglądu. Ten system operacyjny znacznie się poprawił w ostatnich l...
Gry Jak przechwytywać i przesyłać strumieniowo sesję gry w systemie Linux
Jak przechwytywać i przesyłać strumieniowo sesję gry w systemie Linux
W przeszłości granie w gry było uważane tylko za hobby, ale z czasem branża gier odnotowała ogromny wzrost pod względem technologii i liczby graczy. P...