Install OpenCV under Ubuntu

Source: Internet
Author: User

One, dependent package installation

Prerequisites: System Update
sudo apt-get update
sudo apt-get upgrade
Installing software under Ubuntu is more or less required to install some dependent packages (software). OPENCV is no exception.

1. The Build-essential software package, which provides the compiler with a list of required packages, so that the package knows where the header file and library functions are. It also downloads dependent packages, installs basic programming tools such as Gcc/g++/gdb/make, and finally makes up a development environment.

sudo apt-get install build-essential

2. The following dependencies are primarily designed to support reading and writing pictures and videos.

sudo apt-get install Libgtk2.0-dev libavcodec-dev libavformat-dev libtiff4-dev libswscale-dev Libjasper-dev

3. Install CMake, can download the source code compiled online, you can also download the Baidu Network 2.8.12 version, of course, you can use the Apt-get method directly.

sudo apt-get install CMake

4. Install Pkg-config, which is a computer software that provides a unified interface for querying an installed library when compiling software from source code.

sudo apt-get install Pkg-config

5. Other

sudo apt-get install Python-dev python-numpy libtbb2 libtbb-dev libjpeg-dev libpng-dev libtiff-dev libjasper-dev libdc139 4-22-dev
sudo apt-get install Python-dev python-numpy libtbb2 libtbb-dev libjpeg-dev libpng-dev libtiff-dev libjasper-dev libdc139 4-22-dev
Second, download the source code

OpenCV source code can be downloaded from its official website, extracted to the designated directory, such as/home/**/opencv/

cd/home/**/opencv/

third, the process of compiling the source code

1. Using CMake to detect the compilation environment and to generate makefile and other project information, you can set some parameters using the CMake procedure.
Using CMake in this directory, note that the following points indicate looking for CMakeLists.txt in the current directory.
CMake.
2. Compiling with Make
Make
3. Install with make install
sudo make install
4. The above procedure basically completes the installation of the OPENCV. However, it is not possible to use it immediately, OPENCV also contains many dynamic link libraries.

You can add/usr/local/lib to the file/etc/ld.so.conf (this is related to the installation directory, {cmake_install_prefix}/lib),

You can also add a conf file under the/ETC/LD.SO.CONF.D directory (which can be named opencv.conf), as well as adding/usr/local/lib

Equivalent to the following command
Sudo/bin/bash-c ' echo '/usr/local/lib ' >/etc/ld.so.conf.d/opencv.conf '
sudo ldconfig
Use the following Dynamic Library Management command Ldconfig to let the relevant link libraries of OPENCV be shared by the system
sudo ldconfig-v
5. The sharing of dynamic libraries has been completed, it is not possible to program using OPENCV, and the OPENVC header file location for the program needs to be specified. This is done using the Pkg-config command. First, add the/etc/profile in the
Export Pkg_config_path= $PKG _config_path:/usr/local/lib/pkgconfig


Pkg-config maintains a configuration file about OpenCV, a file (opencv.pc) in the directory/usr/local/lib/pkgconfig, which records some of the OPENCV's dynamic library information, as well as header file information

You can list configuration information about OpenCV by using the Pkg-config command:

Pkg-config--libs OpenCV

6 Test OpenCV3.0
Switch to the Samples directory under OpenCV3.0 and compile the samples program
CD opencv/samples/
sudo cmake.
sudo make-j $ (nproc)
Then switch to the CPP directory
CD cpp/
./cpp-example-facedetect lena.jpg



Uninstall Ubuntu

Enter the build file for the installation package to execute:

Make Uninstall

Cd..

sudo rm-r build

sudo rm-r/usr/local/include/opencv2/usr/local/include/opencv/usr/include/opencv/usr/include/opencv2/usr/local/ share/opencv/usr/local/share/opencv/usr/share/opencv/usr/share/opencv/usr/local/bin/opencv*/usr/local/lib/ libopencv*

Reference:

http://blog.csdn.net/linj_m/article/details/45048905

http://blog.csdn.net/surgewong/article/details/39078251#

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.