Install prerequirements
$ 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
$ sudo apt-get install libavcodec-dev libavformat-dev libswscale-dev libv4l-dev
$ sudo apt-get install libxvidcore-dev libx264-dev
$ sudo apt-get install libgtk-3-dev
$ sudo apt-get install libatlas-base-dev gfortran
$ sudo apt-get install python2.7-dev python3.5-dev
To be able to use with python3, you should install pip3 first
$ sudo apt-get update
$ sudo apt-get -y install python3-pip
$ sudo apt-get update
Make a build folder and generate with cmake
$ cd Documents
Download the data from my drive with this link:
Download from GDrive
Remove my built files and then build yours
$ cd ~/Documents/opencv-3.3.0/
$ rm -rf build
$ mkdir build
$ cd build
Configuration of the cmake
$ cmake -D CMAKE_BUILD_TYPE=RELEASE \
-D CMAKE_INSTALL_PREFIX=/usr/local \
-D INSTALL_PYTHON_EXAMPLES=ON \
-D INSTALL_C_EXAMPLES=OFF \
-D WITH_CUDA=ON \
-D ENABLE_FAST_MATH=1 \
-D CUDA_FAST_MATH=1 \
-D WITH_CUBLAS=1 \
-D OPENCV_EXTRA_MODULES_PATH=~/Documents/opencv_contrib-3.3.0/modules \
-D BUILD_EXAMPLES=ON \
-D BUILD_opencv_xfeatures2d=OFF ..
Depend on your number of core nproc, mine 20
$ make -j20
Install
$ sudo make install
$ sudo ldconfig
Depend on your path
$ ls -l /usr/local/lib/python2.7/site-packages
Or
$ ls -l /usr/local/lib/python2.7/dist-packages
total 2092
-rw-r–r– 1 root staff 2138812 Jun 2 14:11 cv2.so
To verify, simply run:
$ python
>> import cv2
>> cv2.__version__
>> exit()
$ python3
>> import cv2
>> cv2.__version__
>> exit()