Installing OpenCV 3.1.0 And opencv-contrib packages
First of all, please noet that the following guide has been taken from the OpenCV documentation itself, but with minor changes required to install version 3.1.0 and contrib package of OpenCV.
Preparation
The very first step is to make sure you have required packages (build tools like gcc compiler, cmake, git, etc.). Use the following commands to download the required packages (do not be worried, if you already have them the package manager will not download or install already existing packages)
First, build tools:
1
|
$
sudo
apt
-
get
install
build
-
essential
|
Then the required packages:
1
|
$
sudo
apt
-
get
install
cmake
git
libgtk2
.
0
-
dev
pkg
-
config
libavcodec
-
dev
libavformat
-
dev
libswscale
-
dev
|
*Optional packages:
1
|
$
sudo
apt
-
get
install
python
-
dev
python
-
numpy
libtbb2
libtbb
-
dev
libjpeg
-
dev
libpng
-
dev
libtiff
-
dev
libjasper
-
dev
libdc1394
-
22
-
dev
|
Downloading OpenCV source files
I assume that you want to download sources into “/opt/” folder. Feel free to change the base directory to wherever you want (granted that you have write access) but make sure to reflect the changes in the code snippets below!.
Clone OpenCV’s git repository:
1
|
/
opt
$
git
clone
https
:
//github.com/Itseez/opencv.git
|
After this, stay in the “/opt” folder and clone the contrib repository as well (if you need the extra packages)
1
|
/
opt
$
git
clone
https
:
//github.com/Itseez/opencv_contrib.git
|
After cloning both repositories, you will have two folders. First “opencv” and second “opencv_contrib”. Now you have to go to each folder and make sure to checkout the version 3.1.0 branch for both of them (It is important that the version of OpenCV and OpenCV Contrib packages match!):
As of Jun 2016 please leave both the opencv and opencv_contrib repositories to stay on Master branch. you do not need to check out 3.1.0…the code snippets are just here for example! do not checkout other branches!
1
2
3
4
5
|
/
opt
$
cd
opencv
/
opt
/
opencv
$
git
checkout
3.1.0
/
opt
/
opencv
$
cd
/
opt
/
opencv_contrib
/
opt
/
opencv_contrib
$
git
checkout
3.1.0
/
opt
/
opencv_contrib
$
cd
/
opt
/
opencv
|
The last command should bring you inside the opencv folder. Get ready for the configuration and compilation step!
Pre-Build Configuration
Before compiling OpenCV from source, we need to perform some configuration to let the compiler know what we need it to compile for us! The first step is to create a directory for the compiler to put the complied files there for us. I call this “release” directory:
1
2
3
|
/
opt
/
opencv
$
mkdir
release
/
opt
/
opencv
$
cd
release
/
opt
/
opencv
/
release
$
|
Now we have to let the “cmake” build system know how we want to configure the OpenCV for compilation, while you are in the release folder, type the following command:
1
|
/
opt
/
opencv
/
release
$
cmake
-
D
CMAKE_BUILD_TYPE
=
RELEASE
-
D
CMAKE_INSTALL_PREFIX
=
/
usr
/
local
-
D
OPENCV_EXTRA_MODULES_PATH
=
/
opt
/
opencv_contrib
/
modules
/
opt
/
opencv
/
|
What the command above does, is to tell the cmake that we want to compile a release version, we want the resulted library files to be copied to /usr/local (this is where most shared libraries are installed on a GNU/Linux system) and finally we tell the cmake where the contirb package modules are located. If you do not want to install contrib packages, remove the last option. Finally as I told before, the double dot tells the cmake that source codes are one folder up in the folder structure! After this step, you should see some files and folders in the release folder (as well as the “Makefile” generatd by cmake).
Note that this is default configuration. If you want to have FFMPEG and CUDA support, you have to first install these libraries and edit the CMakeCache.txt to enable these features!
Make and install
This is the final step. The only thing you need to do is to call “make” command in release folder, wait for compilation (it might take up to one hour depending on your computer’s processing power!) and finally install the compiled libraries by calling “make install”. To do so:
1
2
|
/
opt
/
opencv
/
release
$
make
/
opt
/
opencv
/
release
$
sudo
make
install
|
That’s all folks! hopefully if you have done everything right, your installation should be done by now! To check, run the following command:
1
|
$
pkg
-
config
--
modversion
opencv
|
It should print out “3.1.0”…