下载opencv和opencv_contrib,cmake过程中要下载的一些包可以手动下载配置,如果网络较好,也可以等待自动下载。主要记录的是cmake命令:
cmake -D CMAKE_BUILD_TYPE=RELEASE \-D BUILD_opencv_python3=YES \-D CMAKE_INSTALL_PREFIX=/usr/local/opencv4_5_0 \-D WITH_TBB=ON \-D ENABLE_FAST_MATH=1 \-D CUDA_FAST_MATH=1 \-D WITH_CUBLAS=1 \-D WITH_CUDA=ON \-D BUILD_opencv_cudacodec=On \-D WITH_CUDNN=ON \-D CUDA_ARCH_BIN=8.6 \-D WITH_OPENGL=ON \-D WITH_OPENCL=ON \-D WITH_GSTREAMER=ON \-D OPENCV_GENERATE_PKGCONFIG=ON \-D OPENCV_PC_FILE_NAME=opencv4.pc \-D OPENCV_PYTHON3_INSTALL_PATH=/home/user/data2t/software/anaconda3/envs/py38/lib/python3.8/site-packages \-D OPENCV_ENABLE_NONFREE=ON \-D CUDA_CUDA_LIBRARY=/usr/local/cuda/lib64/stubs/libcuda.so \-D CUDA_TOOLKIT_ROOT_DIR=/usr/local/cuda \-D OpenCL_LIBRARY=/usr/local/cuda/lib64/libOpenCL.so \-D CUDNN_LIBRARY=/usr/local/cuda/lib64/libcudnn.so \-D OpenCL_INCLUDE_DIR=/usr/local/cuda/include \-D OPENCV_EXTRA_MODULES_PATH=/home/user/data1t/3rdparty/opencv-4.5.0/opencv_contrib/modules \-D PYTHON3_LIBRARIES=/home/user/data2t/software/anaconda3/envs/py38/lib/libpython3.8.so \-D PYTHON3_PACKAGES_PATH=/home/user/data2t/software/anaconda3/envs/py38/lib/python3.8/site-packages \-D PYTHON3_INCLUDE_PATH=/home/user/data2t/software/anaconda3/envs/py38/include/python3.8 \-D INSTALL_PYTHON_EXAMPLES=ON \-D INSTALL_C_EXAMPLES=ON \-D BUILD_SHARED_LIBS=ON \-D BUILD_EXAMPLES=ON .. \-D BUILD_opencv_python2=OFF \-D BUILD_opencv_python3=ON \-D HAVE_opencv_cudaarithm=ON \-D HAVE_opencv_cudawarping=ON \-D PYTHON3_EXECUTABLE=/home/user/data2t/software/anaconda3/envs/py38/bin/pythonmake -j 12
sudo make install
这里有个opencv编译参数一览表:https://blog.csdn.net/qq_31112205/article/details/107039695