CUDA

Posted by Cluster on October 19, 2021

如何编译OpenCV使能Cuda

卸载软件库预装OpenCV

1
sudo apt-get purge libopencv*

装个新的

  • 1
    2
    3
    4
    5
    
    mkdir opencv_with_Cuda
    cd opencv_with_Cuda
    git clone https://github.com/opencv/opencv.git
    cd opencv
    git checkout -b 3.4.3
    
  • 1
    2
    3
    4
    
    cd ..
    git clone https://github.com/opencv/opencv_contrib.git
    cd opencv_contrib
    git checkout -b 3.4.3
    
  • 1
    2
    3
    4
    5
    6
    7
    8
    
    cd ../opencv
    mkdir build
    cd build
    #cmake
    cmake -D CMAKE_BUILD_TYPE=RELEASE -D INSTALL_C_EXAMPLES=ON -D INSTALL_PYTHON_EXAMPLES=ON -D OPENCV_EXTRA_MODULES_PATH=../../opencv_contrib/modules -D BUILD_EXAMPLES=ON -D BUILD_opencv_python2=OFF -D BUILD_opencv_python3=ON -D WITH_FFMPEG=ON -D WITH_LIBV4L=ON -D WITH_GTK=ON -D WITH_OPENGL=ON -D WITH_ZLIB=ON -D BUILD_PNG=ON -D BUILD_JPEG=ON -D BUILD_TIFF=ON -D WITH_CUDA=ON -D WITH_OPENCL=ON -D ENABLE_FAST_MATH=1 -D CUDA_FAST_MATH=1 -D WITH_CUBLAS=1 -D WITH_LAPACK=OFF -DCMAKE_INSTALL_PREFIX=/usr/local -D PYTHON3_EXECUTABLE=$(which python) -D PYTHON3_INCLUDE_DIR=$(python -c "from distutils.sysconfig import get_python_inc; print(get_python_inc())") -DPYTHON3_PACKAGES_PATH=$(python -c "from distutils.sysconfig import get_python_lib; print(get_python_lib())") ..
    #cmake完以后看一下CUDA和python3的相关输出,有可能python3会没有显示,不影响,CUDA处的参数一定要是YES
    make -j8
    sudo make install