Build OpenCV with CUDA

Get source from OpenCV official repository

Extract each file.

$ cd ~/Downloads
$ tar zxf opencv-3.4.0.tar.gz
$ tar zxf opencv_contrib-3.4.0.tar.gz

$ cd opencv-3.4.0
$ mkdir build
$ cd build

cmake using this options.

$ cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -DOPENCV_EXTRA_MODULES_PATH=../../opencv_contrib-3.4.0/modules -D FORCE_VTK=ON -D WITH_TBB=ON -D WITH_V4L=ON -D WITH_QT=ON -D WITH_OPENGL=ON -D WITH_CUBLAS=ON -D CUDA_NVCC_FLAGS="-D_FORCE_INLINES" -D WITH_GDAL=ON -D WITH_XINE=ON -D BUILD_EXAMPLES=ON -D CUDA_FAST_MATH=-ON ..

Build & install

$ make -j8
$ sudo make install

Check you PATH environment, append /usr/local/bin

$ echo 'export PATH=/usr/local/bin:$PATH' | tee -a ~/.bashrc
$ source ~/.bashrc

Check installation

$ opencv_version
3.4.0
$ which opencv_version
/usr/local/bin/opencv_version