Ubuntu安装配置opencv

配置如下:
GTX2080ti / Ubuntu16.04 / cuda10.2 / cudnn8.0.3 / tensorrt8.2.0 / opencv3.4.10
缺少:tensorrt8.2.0 opencv3.4.10
准备工作:
查看cudnn版本,这里需要注意的是:新版本的cudnn与旧版本不同,cudnn的版本写在了_version.h文件中。如果安装的时候没有放入到include中,那么你无法查到版本号。

cat /usr/local/cuda/include/cudnn_version.h | grep CUDNN_MAJOR -A 2

安装Opencv

1.官网下载安装包

Source:https://opencv.org/releases/

2.解压并进入到opencv中

解压完别忘了挪到你工作的位置,别在download下操作

unzip opencv-3.4.10
cd opencv-3.4.10

3.安装cmake工具

sudo apt-get install cmake
sudo apt-get update

出现如下问题:

/sbin/ldconfig.real: /usr/local/cuda-10.2/targets/x86_64-linux/lib/libcudnn_adv_train.so.8 is not a symbolic link
/sbin/ldconfig.real: /usr/local/cuda-10.2/targets/x86_64-linux/lib/libcudnn_cnn_infer.so.8 is not a symbolic link
/sbin/ldconfig.real: /usr/local/cuda-10.2/targets/x86_64-linux/lib/libcudnn.so.8 is not a symbolic link
/sbin/ldconfig.real: /usr/local/cuda-10.2/targets/x86_64-linux/lib/libcudnn_ops_infer.so.8 is not a symbolic link
/sbin/ldconfig.real: /usr/local/cuda-10.2/targets/x86_64-linux/lib/libcudnn_adv_infer.so.8 is not a symbolic link
/sbin/ldconfig.real: /usr/local/cuda-10.2/targets/x86_64-linux/lib/libcudnn_ops_train.so.8 is not a symbolic link

真是难受,是软链接的问题,这里输入如下命令,将软链接接上

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

4.安装依赖库

sudo apt-get install build-essential libgtk2.0-dev libavcodec-dev libavformat-dev libjpeg.dev libtiff4.dev libswscale-dev libjasper-dev

5.创建编译目录(release)并进入:

mkdir release && cd release

6.cmake配置编译

cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D WITH_TBB=ON -D BUILD_NEW_PYTHON_SUPPORT=ON -D WITH_V4L=ON -D WITH_QT=ON -D WITH_OPENGL=ON ..

7.make

make -j$(nproc) 

[注]nproc是读取CPU的核心数量

8.安装

sudo make install

9. 添加环境路径

sudo gedit /etc/ld.so.conf.d/opencv.conf 
/usr/local/lib

10.更新系统库:

sudo ldconfig

11.配置bash,执行如下命令

sudo gedit /etc/bash.bashrc  
//在末尾添加
PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig  
export PKG_CONFIG_PATH

12.保存退出,然后执行如下命令使得配置生效,激活配置然后更新database

sudo source /etc/bash.bashrc
sudo updatedb  

至此所有的配置都已经完成

测试

【注】测试安装是否正确

下面用一个官方自带sample测试一下

cd opencv-3.4.1/samples/cpp/example_cmake

我们可以看到这个目录里官方已经给出了一个cmake的example我们可以拿来测试下

cmake .
make
./opencv_example

在make这一步报错:
问题一:
应该是找不到这个库:

warning: libicui18n.so.58, needed by anaconda3/lib/libQt5Core.so.5

解决办法:

sudo gedit /etc/profile

在文件末尾添加下列语句。

export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/home/jh/anaconda3/lib

保存之后,source一下。

source /etc/profile

问题二:

usr/bin/cmake: /home/jh/anaconda3/lib/libcurl.so.4: no version information available (required by /usr/bin/cmake)
/usr/bin/cmake: /home/jh/anaconda3/lib/libcurl.so.4: no version information available (required by /usr/bin/cmake)
/usr/bin/cmake: /home/jh/anaconda3/lib/libcurl.so.4: no version information available (required by /usr/bin/cmake)
/usr/bin/cmake: /home/jh/anaconda3/lib/libcurl.so.4: no version information available (required by /usr/bin/cmake)

cmake应该是冲突了,就是版本之间有冲突,因为linux本身就是有cmake的,安装了之后软链接需要修改。
解决办法:
首先定位看下libcurl.so.4的位置

locate libcurl.so.4

出现如下信息:

/home/jh/anaconda3/lib/libcurl.so.4
/home/jh/anaconda3/lib/libcurl.so.4.7.0
/home/jh/anaconda3/pkgs/libcurl-7.78.0-h0b77cf5_0/lib/libcurl.so.4
/home/jh/anaconda3/pkgs/libcurl-7.78.0-h0b77cf5_0/lib/libcurl.so.4.7.0
/usr/lib/x86_64-linux-gnu/libcurl.so.4
/usr/lib/x86_64-linux-gnu/libcurl.so.4.4.0

看下 /home/jh/anaconda3/lib/libcurl.so.4的软链接:

ll /home/jh/anaconda3/lib/libcurl.so.4

得到如下信息:

/home/jh/anaconda3/lib/libcurl.so.4 -> libcurl.so.4.7.0*

需要将 /home/jh/anaconda3/lib/libcurl.so.4 映射成如下:

/home/jh/anaconda3/lib/libcurl.so.4 -> /usr/lib/x86_64-linux-gnu/libcurl.so.4.4.0

操作如下:

//先删除
sudo rm -rf /home/jh/anaconda3/lib/libcurl.so.4
//再添加
sudo ln -s /usr/lib/x86_64-linux-gnu/libcurl.so.4.4.0 /home/jh/anaconda3/lib/libcurl.so.4

在如上编译测试即可,即可出现hello opencv!

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