How to install OpenCV Ubuntu

Chưa phân loại

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:

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 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 <iostream>

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


ONET IDC thành lập vào năm 2012, là công ty chuyên nghiệp tại Việt Nam trong lĩnh vực cung cấp dịch vụ Hosting, VPS, máy chủ vật lý, dịch vụ Firewall Anti DDoS, SSL… Với 10 năm xây dựng và phát triển, ứng dụng nhiều công nghệ hiện đại, ONET IDC đã giúp hàng ngàn khách hàng tin tưởng lựa chọn, mang lại sự ổn định tuyệt đối cho website của khách hàng để thúc đẩy việc kinh doanh đạt được hiệu quả và thành công.
Bài viết liên quan

bash date examples

Bash uses `date` command to display or change the current date and time value of the system. Date and time value can be...

Tmux vs. Screen tool comparison

A Terminal multiplexer is a program that can be used to multiplex login sessions inside the Terminal. This allows users...

How to Install CentOS 8 on VirtualBox

In this article, I am going to show you how to install CentOS 8 in a VirtualBox virtual machine. So, let’s get started. Downloading...
Bài Viết

Bài Viết Mới Cập Nhật

Mua Proxy V6 Nuôi Facebook Spam Hiệu Quả Tại Onetcomvn

Hướng dẫn cách sử dụng ProxyDroid để duyệt web ẩn danh

Mua proxy Onet uy tín tại

Thuê mua IPv4 giá rẻ, tốc độ nhanh, uy tín #1

Thuê địa chỉ IPv4 IPv6 trọn gói ở đâu chất lượng, giá RẺ nhất?