opencv4.5.1 带cuda11.0 cudnn8.0.5编译

参考链接

https://blog.csdn.net/fixed_zhang/article/details/110428259?utm_medium=distribute.pc_relevant.none-task-blog-BlogCommendFromMachineLearnPai2-1.control&depth_1-utm_source=distribute.pc_relevant.none-task-blog-BlogCommendFromMachineLearnPai2-1.control#commentBox

操作步骤

  1. 码云上下载opencv + opencv_contrib源码(速度比github快)
git clone -b 4.5.1 https://gitee.com/Tengyun_Mo/opencv.git
mv opencv opencv-4.5.1
cd opencv-4.5.1
git clone -b 4.5.1 https://gitee.com/Tengyun_Mo/opencv_contrib.git
mv opencv_contrib opencv_contrib-4.5.1
mkdir build
cd build
  1. anzhuayilai
sudo apt install -y build-essential cmake git pkg-config libopenexr-dev libblas-dev 
sudo apt install -y python-dev python-numpy libtbb2 libtbb-dev
sudo apt install -y libjpeg-dev libpng-dev libtiff-dev libdc1394-22-dev libjasper-dev
sudo apt install -y libavcodec-dev libavformat-dev libswscale-dev libavutil-dev
sudo apt-get install libgphoto2-dev libeigen3-dev libhdf5-dev doxygen

sudo apt install -y \
        libx264-dev \
        mesa-utils \
        libgtk2.0-dev \
        libxvidcore-dev \
        yasm \
        libxine2-dev \
        libgstreamer1.0-dev libgstreamer-plugins-base1.0-dev \
        libv4l-dev \
        libfaac-dev \
        libmp3lame-dev \
        libopencore-amrnb-dev \
        libtheora-dev \
        libvorbis-dev \
        ffmpeg \
        libeigen3-dev libeigen3-doc \
		liblapack-dev \
        tesseract-ocr \
        tesseract-ocr-jpn \
        libgflags-dev \
        libleptonica-dev \
        libtesseract-dev \
        gphoto2 \
        liblapacke-dev \
        libgoogle-glog-dev \
        libprotobuf-dev \
        libprotoc-dev \
        protobuf-compiler \
        ccache \
        libgphoto2-dev \
        libavresample-dev \
        libatlas-base-dev \
        gfortran

  1. cmake生成makefile文件
cmake -DCMAKE_BUILD_TYPE=RELEASE     -DCMAKE_INSTALL_PREFIX=/usr/local/opencv-4.5.1     -DOPENCV_EXTRA_MODULES_PATH=../opencv_contrib-4.5.1/modules ..     -DWITH_CUDA=1  -DWITH_CUDNN=1 -DWITH_V4L=1 -DOPENCV_DNN_CUDA=1 -D CUDNN_VERSION='8.0.5' -DCUDNN_INCLUDE_DIR='/usr/local/cuda/include/'  -DENABLE_FAST_MATH=1     -DCUDA_FAST_MATH=1     -DWITH_CUBLAS=1    -DCUDA_nppi_LIBRARY=true -DOPENCV_GENERATE_PKGCONFIG=1     -DCUDA_GENERATION=Pascal ..

查看cuda与cudnn是否支持
opencv4.5.1 带cuda11.0 cudnn8.0.5编译_第1张图片

  1. 编译源码
make -j4
  1. 安装opencv
sudo make install
  1. huanjingdajian
# 编辑/etc/bash.bashrc
sudo gedit /etc/bash.bashrc
# 在文件末尾添加
PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/opencv-4.5.1/lib/pkgconfig
export PKG_CONFIG_PATH
# 退出并更新
sudo updatedb

# 编辑/etc/ld.so.conf.d/opencv.conf
sudo gedit /etc/ld.so.conf.d/opencv.conf
# 在文件末尾添加
/usr/local/opencv-4.5.1/lib
# 退出并更新
sudo ldconfig

你可能感兴趣的:(opencv,cuda,cudnn)