cuda10.2+opencv4.1.2编译cuda版本opencv

opencv官网

cmake demo

cmake     -DCMAKE_BUILD_TYPE=Release     -DCMAKE_INSTALL_PREFIX=/usr/local     -DBUILD_PNG=OFF     -DBUILD_TIFF=OFF     -DBUILD_TBB=OFF     -DBUILD_JPEG=OFF     -DBUILD_JASPER=OFF     -DBUILD_ZLIB=OFF     -DBUILD_EXAMPLES=ON     -DBUILD_opencv_java=OFF     -DBUILD_opencv_python2=ON     -DBUILD_opencv_python3=ON     -DENABLE_PRECOMPILED_HEADERS=OFF     -DWITH_OPENCL=OFF     -DWITH_OPENMP=OFF     -DWITH_FFMPEG=ON     -DWITH_GSTREAMER=ON     -DWITH_GSTREAMER_0_10=OFF     -DWITH_CUDA=ON     -DWITH_GTK=ON     -DWITH_VTK=OFF     -DWITH_TBB=ON     -DWITH_1394=OFF     -DWITH_OPENEXR=OFF     -DCUDA_TOOLKIT_ROOT_DIR=/usr/local/cuda-10.2     -DCUDA_ARCH_BIN=6.2     -DCUDA_ARCH_PTX=""     -DINSTALL_C_EXAMPLES=OFF     -DINSTALL_TESTS=OFF     ../

第一步 cuda cudnn安装

cuda安装网上示例很多,重点从cudnn开始。本本测试是cuda10.2+cudnn7.6.5

下载cudnn

https://developer.nvidia.com/rdp/cudnn-archive

下载

先安装 libcudnn7_7.6.5.32-1+cuda10.2_amd64.deb
再安装 libcudnn7-dev_7.6.5.32-1+cuda10.2_amd64
dpkg -i XX.deb

第二步 安装依赖

sudo add-apt-repository "deb http://security.ubuntu.com/ubuntu xenial-security main"
sudo apt-get update
sudo apt-get install build-essential
sudo apt-get install libgtk2.0-dev pkg-config libavcodec-dev libavformat-dev libswscale-dev
sudo apt-get install python-dev python-numpy libtbb2 libtbb-dev libjpeg-dev libpng-dev libtiff-dev libjasper-dev libdc1394-22-dev
sudo apt-get install libgtk-3-dev libgtk2.0-dev pkg-config
sudo apt-get install libavcodec-dev libavformat-dev libswscale-dev libv4l-dev liblapacke-dev
sudo apt-get install libopenexr-dev
sudo apt-get install libxvidcore-dev libx264-dev
sudo apt-get install ffmpeg
sudo apt-get install git gfortran
sudo apt-get install libjpeg8-dev libpng12-dev
sudo apt-get install libtiff5-dev
sudo apt-get install libxine2-dev
sudo apt install -y libgstreamer1.0-dev libgstreamer-plugins-base1.0-dev
sudo apt-get install qt5-default libgtk2.0-dev libtbb-dev
sudo apt-get install libatlas-base-dev
sudo apt-get install libfaac-dev libmp3lame-dev libtheora-dev
sudo apt-get install libvorbis-dev libxvidcore-dev
sudo apt-get install libopencore-amrnb-dev libopencore-amrwb-dev
sudo apt-get install x264 v4l-utils
sudo apt-get install libprotobuf-dev protobuf-compiler
sudo apt-get install libgoogle-glog-dev libgflags-dev
sudo apt-get install libgphoto2-dev libeigen3-dev libhdf5-dev doxygen
sudo apt install libopenblas-base libopenblas-dev
sudo apt-get install freeglut3-dev
sudo apt-get install libgtk3*


简化版系统更新

$ sudo apt-get update
$ sudo apt-get upgrade
$ sudo apt-get install build-essential cmake unzip pkg-config
$ sudo apt-get install libjpeg-dev libpng-dev libtiff-dev
$ sudo apt-get install libavcodec-dev libavformat-dev libswscale-dev
$ sudo apt-get install libv4l-dev libxvidcore-dev libx264-dev
$ sudo apt-get install libgtk-3-dev
$ sudo apt-get install libatlas-base-dev gfortran
$ sudo apt-get install python3-dev


第三步 安装opencv_contrib.

wget -O opencv_contrib.zip https://hub.fastgit.org/opencv/opencv_contrib/archive/master.zip

将opencv_contrib 中的cudev移到opencv moduels下;去除opencv_contrib 中不需要的库文件如face等

opencv_contrib 官网https://github.com/opencv/opencv_contrib/tree/4.1.2

第四步 cmake make.

cmake -DOPENCV_EXTRA_MODULES_PATH=../../opencv_contrib-master/modules/ ../../opencv-4.1.2/ -DWITH_CUDA=ON -DBUILD_opencv_python3=OFF -DBUILD_opencv_python2=OFF  -DBUILD_TESTS=OFF -DWITH_OPENGL=ON ../

make -j8完成编译

make install安装到系统
链接库共享
编译安装完毕之后,为了让你的链接库被系统共享,让编译器发现,需要执行管理命令ldconfig:

sudo ldconfig -v  

参考文章

  • https://blog.csdn.net/wq1psa78/article/details/105334859
  • https://blog.csdn.net/GungnirsPledge/article/details/108597474
  • https://blog.csdn.net/weixin_45617478/article/details/104111789
  • opencv编译带cuda
  • opencv_contrib安装笔记
  • opencv4.2+opencv_contrib编译gpu加速带cuda和CUDnn(二)

你可能感兴趣的:(NVIDIA,GPU,opencv,linux,ubuntu)