安装前置依赖
sudo apt-get install build-essential
[required] sudo apt-get install cmake git libgtk2.0-dev pkg-config libavcodec-dev libavformat-dev libswscale-dev
[optional] sudo apt-get install python-dev python-numpy libtbb2 libtbb-dev libjpeg-dev libpng-dev libtiff-dev libjasper-dev libdc1394-22-dev
CMake配置
git clone https://github.com/opencv/opencv.git
git clone https://github.com/opencv/opencv_contrib.git
cd opencv
mkdir build
cd build
cmake -DWITH_CUDA=ON -D ENABLE_FAST_MATH=1 -DCUDA_NVCC_FLAGS=--expt-relaxed-constexpr -DWITH_FFMPEG=1 -DINSTALL_C_EXAMPLES=OFF -DBUILD_EXAMPLES=ON -D OPENCV_EXTRA_MODULES_PATH=../../opencv_contrib/modules -DBUILD_opencv_cudaarithm=ON -DBUILD_opencv_cudabgsegm=ON -DBUILD_opencv_cudafeatures2d=OFF -DBUILD_opencv_cudafilters=ON -DBUILD_opencv_cudaimgproc=ON -DBUILD_opencv_cudalegacy=ON -DBUILD_opencv_cudaobjdetect=ON -DBUILD_opencv_cudaoptflow=ON -DBUILD_opencv_cudastereo=OFF -DBUILD_opencv_cudawarping=ON -DBUILD_opencv_cudacodec=ON -DBUILD_opencv_viz=OFF -DBUILD_opencv_stereo=OFF -DBUILD_opencv_tracking=OFF -DBUILD_opencv_sfm=OFF -D CUDA_FAST_MATH=1 -D WITH_CUBLAS=1 ..
make install