Abstract
This article aims at installing OpenCV 3.4.8 with opencv_contrib environment on Ubuntu 16.04.
Note: Though this is for Ubuntu 16.04.6, it may still adapt to the similar version like Ubuntu 18.04.
Note: Though this is for OpenCV 3.4.8, it may still adapt to the similar version.
Step 1. Install dependences
Install dependences required:
~$ sudo apt-get install build-essential
~$ sudo apt-get install cmake git libgtk2.0-dev pkg-config libavcodec-dev libavformat-dev libswscale-dev
~$ sudo apt-get install python-dev python-numpy libtbb2 libtbb-dev libjpeg-dev libpng-dev libtiff-dev libjasper-dev libdc1394-22-dev
Attention: This dependences are for version 3.4.8, for other version, please see official documents in https://opencv.org/.
Step 2. Download sources
Download OpenCV 3.4.8 source file(source.zip) from Github repo: https://github.com/opencv/opencv/releases/tag/3.4.8
Download OpenCV_Contrib 3.4.8 source file(source.zip) from Github repo: https://github.com/opencv/opencv_contrib/releases/tag/3.4.8
Attention: Please make sure the version of OpenCV and OpenCV_Contrib are the same, otherwise it will install failure.
Step 3. Unzip and move files
Unzip the two downloaded files in the same directory, take ~/ as an example:
~$ unzip opencv-3.4.8.zip
~$ unzip opencv_contrib-3.4.8.zip
Now two folder will appear in the ~/ directory:
opencv-3.4.8
opencv_contrib-3.4.8
Move the folder opencv_contrib-3.4.8 to the folder opencv-3.4.8:
~$ mv opencv_contrib-3.4.8 opencv-3.4.8
Step 4. Building OpenCV from Source Using CMake
Create a new folder “build” in the folder “opencv-3.4.8”:
~$ cd opencv-3.4.8
~/opencv-3.4.8$ mkdir build
~/opencv-3.4.8$ cd build
Configuring with cmake commands:
cmake -D CMAKE_BUILD_TYPE=Release -D CMAKE_INSTALL_PREFIX=/usr/local -DOPENCV_EXTRA_MODULES_PATH=/home/<yourusername>/opencv-3.4.8/opencv_contrib-3.4.8/modules ..
If no error occurs, run command below to make the project:
~/opencv-3.4.8/build$ make -j7
If no error occurs, run command below to install:
sudo make install
Finally, run command below to reload config and reboot:
sudo ldconfig
reboot