Installing OpenCV 3.1.0 and contrib on Ubuntu

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:

Then the required packages:

*Optional packages:

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:

After this, stay in the “/opt” folder and clone the contrib repository as well (if you need the extra packages)

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!

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:

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:

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:

That’s all folks! hopefully if you have done everything right, your installation should be done by now! To check, run the following command:

It should print out “3.1.0”…


猜你喜欢

转载自blog.csdn.net/u014679795/article/details/79740506