Compiling OpenCV 3.3 with extra contributed modules

OpenCV extra modules are easy to add on with this procedure for Python.

cd /tmp

git clone https://github.com/Itseez/opencv.git

cd /tmp/opencv

git checkout tags/3.3.0

mkdir release
cd release 

cmake -D OPENCV_EXTRA_MODULES_PATH=../opencv_contrib/modules/ -DBUILD_TIFF=ON -DBUILD_opencv_java=OFF -DWITH_CUDA=OFF -DENABLE_AVX=ON -DWITH_OPENGL=ON -DWITH_OPENCL=ON -DWITH_IPP=ON -DWITH_TBB=ON -DWITH_EIGEN=ON -DWITH_V4L=ON -DBUILD_TESTS=OFF -DBUILD_PERF_TESTS=OFF -DCMAKE_BUILD_TYPE=RELEASE -DCMAKE_INSTALL_PREFIX=$(python3 -c "import sys; print(sys.prefix)") -DPYTHON_EXECUTABLE=$(which python3) -DPYTHON_INCLUDE_DIR=$(python3 -c "from distutils.sysconfig import get_python_inc; print(get_python_inc())") -DPYTHON_PACKAGES_PATH=$(python3 -c "from distutils.sysconfig import get_python_lib; print(get_python_lib())") .. 

make -j4
make install

Assuming you have the prereqs installed already.

Test OpenCV Extras

 import cv2 
 x = cv2.bgsegm.createBackgroundSubtractorGMG() 

Notes

Some of the functions you might want like cv2.createBackgroundSubtractorGMG are not in the standard OpenCV 3 package. The newer functions by design go into the opencv_contrib repository.

After the cmake command, scroll back up and check that you see something like (for example, look for bgsegm, that’s one of the opencv_contrib modules)

OpenCV modules: – To be built: core imgproc imgcodecs videoio highgui xobjdetect adas video bgsegm bioinspired flann ml features2d calib3d ccalib face text datasets line_descriptor objdetect optflow photo reg rgbd saliency shape xfeatures2d stitching superres surface_matching videostab ximgproc xphoto python2 tracking ts – Disabled: java world – Disabled by dependency: - – Unavailable: androidcamera cuda cudaarithm cudabgsegm cudacodec cudafeatures2d cudafilters cudaimgproc cudalegacy cudaoptflow cudastereo cudawarping cudev python3 viz cvv matlab

Leave a Comment