Ubuntu20.04/18.04+opencv4.5.2+contrib4.5.2安装

libopencv_cudafilter.so
contrib安装
v0.1.1f.zip
ADE
https://github.com/opencv/ade/tree/release_0.1
opencv安装
GUI方式安装
cmake -DCMAKE_BUILD_TYPE=Release -DOPENCV_GENERATE_PKGCONFIG=ON -DCMAKE_INSTALL_PREFIX=/usr/local/opencv4.5.2/ -DOPENCV_EXTRA_MODULES_PATH=~/downloads/3party/opencv-4.5.2/opencv_contrib-4.5.2/modules/ -DOPENCV_DNN_CUDA=True -DWITH_CUDA=True -DCUDA_ARCH_BIN=8.6 -DBUILD_TESTS=False DOPENCV_GENERATE_PKGCONFIG=ON …

  1. sudo vim /etc/apt/sources.list 配置
    deb http://security.ubuntu.com/ubuntu/ focal-security universe restricted main multiverse
    deb http://security.ubuntu.com/ubuntu xenial-security main
    deb-src http://security.ubuntu.com/ubuntu xenial-security main
    deb http://archive.ubuntu.com/ubuntu focal-updates main
  2. v0.1.1f.zip
~/downloads/3party/opencv-4.5.2/modules/gapi/cmake/
md5sum v0.1.1f.zip
// 修改DownloadADE.cmake:
#set(ade_md5 "b624b995ec9c439cbc2e9e6ee940d3a2")   
set(ade_md5 "new     hd5!!!!!!!!!")  
“file::///home/zzy/downloads/“
  1. hdf5
    sudo apt install libhdf5-dev libhdf5-103
  2. gtk
    sudo apt-get install libgtk2.0-dev libgtk-3-dev
  3. cuda(诸如:cudaarithm、filter、warping等错误)报错(cudnn 路径没有找到):
    下载 deb 文件:
    1.官网下载地址cuDNN下载地址需要登录nvidia账号,下载对应的deb文件
    2.dpkg -i libcudnn8_8.1.1.33-1+cuda11.2_amd64.deb
    3.dpkg -i libcudnn8-dev_8.1.1.33-1+cuda11.2_amd64.deb
    原文链接:地址
    借鉴(软链接)连接:地址
    另外:set(CMAKE_CXX_FLAGS “${CMAKE_CXX_FLAGS} -D_FORCE_INLINES”)加在opencv文件夹下的 CMakeLists.txt 文件下。(可选)
    deb 文件可理解为深入下载,包含了很多cuda版本的文件,可能是在下载时直接选择软连接作为路径导致的路径找不到产生的问题。
  4. 路径配置
    1.sudo gedit /etc/ld.so.conf.d/opencv4.conf
    2.加入 /usr/local/opencv4.5.2/lib
    3.sudo ldconfig
    4.sudo gedit /etc/bash.bashrc
    5.PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/opencv4.5.2/lib/pkgconfig
    export PKG_CONFIG_PATH
    6.source /etc/bash.bashrc
    7.sudo updatedb
    8.检验版本:pkg-config --modversion opencv4
    9.符号链接报错:
    以为只生成了 cudnn 搭配的版本号,但没有具体的详细版本号,所以需要 sudo ln -sf 将实际版本的 cudnn 静态文件库连接到符号链接上,才能使用。
    sudo ln -sf /usr/local/cuda-11.2/targets/x86_64-linux/lib/libcudnn.so.8.1.1 /usr/local/cuda-11.2/targets/x86_64-linux/lib/libcudnn.so.8
    sudo ln -sf /usr/local/cuda-11.2/targets/x86_64-linux/lib/libcudnn_ops_infer.so.8.1.1 /usr/local/cuda-11.2/targets/x86_64-linux/lib/libcudnn_ops_infer.so.8
    sudo ln -sf /usr/local/cuda-11.2/targets/x86_64-linux/lib/libcudnn_adv_infer.so.8.1.1 /usr/local/cuda-11.2/targets/x86_64-linux/lib/libcudnn_adv_infer.so.8
    sudo ln -sf /usr/local/cuda-11.2/targets/x86_64-linux/lib/libcudnn_cnn_train.so.8.1.1 /usr/local/cuda-11.2/targets/x86_64-linux/lib/libcudnn_cnn_train.so.8
    sudo ln -sf /usr/local/cuda-11.2/targets/x86_64-linux/lib/libcudnn_ops_train.so.8.1.1 /usr/local/cuda-11.2/targets/x86_64-linux/lib/libcudnn_ops_train.so.8
    sudo ln -sf /usr/local/cuda-11.2/targets/x86_64-linux/lib/libcudnn_cnn_infer.so.8.1.1 /usr/local/cuda-11.2/targets/x86_64-linux/lib/libcudnn_cnn_infer.so.8
    sudo ln -sf /usr/local/cuda-11.2/targets/x86_64-linux/lib/libcudnn_adv_train.so.8.1.1 /usr/local/cuda-11.2/targets/x86_64-linux/lib/libcudnn_adv_train.so.8
    10.sudo ldconfig
    11.pkg-config --modversion opencv4
    路径配置
    ldconfig报错处理
    错误详解

cuda 切换版本

sudo rm -rf cuda
sudo ln -s /usr/local/cuda-11.2 /usr/local/cuda

sudo ln -sf /usr/local/cuda-11.0/targets/x86_64-linux/lib/libcudnn.so.8.1.1 /usr/local/cuda-11.0/targets/x86_64-linux/lib/libcudnn.so.8
sudo ln -sf /usr/local/cuda-11.0/targets/x86_64-linux/lib/libcudnn_ops_infer.so.8.1.1 /usr/local/cuda-11.0/targets/x86_64-linux/lib/libcudnn_ops_infer.so.8
sudo ln -sf /usr/local/cuda-11.0/targets/x86_64-linux/lib/libcudnn_adv_infer.so.8.1.1 /usr/local/cuda-11.0/targets/x86_64-linux/lib/libcudnn_adv_infer.so.8
sudo ln -sf /usr/local/cuda-11.0/targets/x86_64-linux/lib/libcudnn_cnn_train.so.8.1.1 /usr/local/cuda-11.0/targets/x86_64-linux/lib/libcudnn_cnn_train.so.8
sudo ln -sf /usr/local/cuda-11.0/targets/x86_64-linux/lib/libcudnn_ops_train.so.8.1.1 /usr/local/cuda-11.0/targets/x86_64-linux/lib/libcudnn_ops_train.so.8
sudo ln -sf /usr/local/cuda-11.0/targets/x86_64-linux/lib/libcudnn_cnn_infer.so.8.1.1 /usr/local/cuda-11.0/targets/x86_64-linux/lib/libcudnn_cnn_infer.so.8
sudo ln -sf /usr/local/cuda-11.0/targets/x86_64-linux/lib/libcudnn_adv_train.so.8.1.1 /usr/local/cuda-11.0/targets/x86_64-linux/lib/libcudnn_adv_train.so.8

cmake -DCMAKE_BUILD_TYPE=Release -DOPENCV_GENERATE_PKGCONFIG=ON -DCMAKE_INSTALL_PREFIX=/usr/local/opencv4.4.0 -DOPENCV_EXTRA_MODULES_PATH=/home/zzy/downloads/3party/opencv-4.4.0/opencv_contrib-4.4.0/modules -DOPENCV_DNN_CUDA=True -DWITH_CUDA=True -DCUDA_ARCH_BIN=8.6 -DBUILD_TESTS=False DOPENCV_GENERATE_PKGCONFIG=ON -DCMAKE_CXX_STANDARD=14 …
gcc-9

set(CMAKE_CXX_FLAGS “-std=c++11”)
set(CMAKE_CXX_STANDARD 14).

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