Install OpenCV 3 non-free module on Ubuntu
The opencv_nonfree
module provides very useful features such as two prominent image features SIFT and SURF (including the CUDA’s implementation). In this tutorial, I demonstrate how to install this module into OpenCV 3 on Ubuntu.
Prerequisites
- Remove the old version which has been installed in the system.
- Do not install
opencv
viaapt-get
- Install
cmake
:sudo apt-get install cmake
Installation
- Download opencv
git clone https://github.com/opencv/opencv
- Do not download the source from homepage.
- Download the
opencv_contrib
:git clone https://github.com/opencv/opencv_contrib
- Check both
opencv
andopencv_contrib
are the latest versions otherwise we can not compile them.
- Check both
- Extract the source.
cd path/to/opencv-source
Run Cmake: cmake-gui
- In the textbox
Where is the source code
, it should be the path of OpenCV Where to build the binaries
: path to your build directory, e.g,~/opencv/build
- Select
Configure
- When the dialog
CMakeSetup
pops up, configure the compiler according to your system. (Most of the time is to selectUnix Makefiles
as the generator andUse default native compilers
as well.) After automatically generating Makefiles, CMake will show all available settings.
Select
OPENCV>OPENCV_ENALBLE_NONFREE
On
OPENCV>OPENCV_EXTRA_MODULES_PATH
, give the path to foldermodules
insideopencv_contrib
Select
Configure
the project again. On the output window, check whether it producesNon-free algorithms are enabled
.On
BUILD
, make sure that you have selected the appropriate modules for features extraction, e.g,BUILD_opencv_xfeatures2d
.Configure
the project again.Select
Generate
cd /path/to/opencv/build
make all
(To speed up :make all -j8
)make install
Done.