编译opencv_cuda

做个小笔记使用
devtoolset 升级gcc
root权限下

opencv源码目录有.cache目录 需要下载链接别的库 由于墙的原因,我已经下载保存了。链接 https://url25.ctfile.com/f/34628125-649528014-3062c3?p=3005 (访问密码: 3005)

升级到gcc8环境(devtoolset)方式

[root@localhost ~]# yum install centos-release-scl
[root@localhost ~]# yum install devtoolset-8
[root@localhost ~]# scl enable devtoolset-8 bash
# 如果需要设置为永久环境  centos下可以这样做
[root@localhost home]# echo "source /opt/rh/devtoolset-8/enable" >> /etc/bashrc

升级cmake到3.21

[root@localhost home]# mkdir cmake
[root@localhost home]# cd cmake/
[root@localhost cmake]# ls
[root@localhost cmake]# wget https://cmake.org/files/v3.21/cmake-3.21.0.tar.gz
[root@localhost cmake]# tar -zvxf cmake-3.21.0.tar.gz
# 安装必要库 OpenSSL
[root@localhost cmake]# yum -y install ncurses-devel
[root@localhost cmake]# yum install openssl-devel 
[root@localhost cmake]# cd cmake-3.21.0
[root@localhost cmake]# yum install ncurses-devel
[root@localhost cmake-3.21.0]# ./configure --prefix=/usr/local/cmake
[root@localhost cmake-3.21.0]# gmake -j16 && gmake install
# 电脑本身有cmake
[root@localhost cmake-3.21.0]# ln -sf /usr/local/cmake/bin/cmake /usr/bin/cmake

编译opencv(带GPU版本)

[root@localhost opencv]# yum install dnf
[root@localhost opencv]# sudo dnf install epel-release git gcc gcc-c++ cmake3 qt5-qtbase-devel python3 python3-devel python3-pip cmake python3-devel python3-numpy gtk2-devel libpng-devel jasper-devel openexr-devel libwebp-devel libjpeg-turbo-devel libtiff-devel tbb-devel libv4l-devel eigen3-devel freeglut-devel mesa-libGL mesa-libGL-devel boost boost-thread boost-devel gstreamer1-plugins-base
# 官网下载了opencv4.5.3 
[root@localhost opencv]# unzip opencv-4.5.3.zip
# 再下载opencv-contrib 源码
[root@localhost opencv]# git clone --recursive https://gitee.com/kui9702/opencv_contrib.git
# 编译  里面在opencv源码目录有.cache目录 需要下载子项目  由于墙的原因,我已经下载保存链接  https://url25.ctfile.com/f/34628125-649528014-3062c3?p=3005 (访问密码: 3005)
[root@localhost opencv-4.5.3]# mkdir build
[root@localhost opencv-4.5.3]# cd build
# [root@localhost build]# cmake -D CMAKE_INSTALL_PREFIX=/usr/local -D INSTALL_PYTHON_EXAMPLES=ON -D INSTALL_C_EXAMPLES=OFF -D OPENCV_ENABLE_NONFREE=ON -D WITH_CUDA=ON -D WITH_CUDNN=ON -D OPENCV_DNN_CUDA=ON -D ENABLE_FAST_MATH=1 -D CUDA_FAST_MATH=1 -D CUDA_ARCH_BIN=7.5 -D WITH_CUBLAS=1 -D OPENCV_EXTRA_MODULES_PATH=/home/opencv/opencv_contrib/modules -D BUILD_EXAMPLES=off -D OPENCV_GENERATE_PKGCONFIG=ON ..
# 可以通过ccmake去配置 
[root@localhost build]#  ccmake3 ../
# 如果ccmake3 找不到
# 可以在cmake/*(省略了中间的文件夹)/bin 目录下可找到ccmake
[root@localhost build]# */ccmake ../
# 先配置了WITH_CUDA ON 然后按C(configure)之后按e重新配置,再配置相关
[root@localhost build]# make -j8
[root@localhost build]# make install
[root@localhost build]# sudo ln -s /usr/local/lib64/pkgconfig/opencv4.pc /usr/share/pkgconfig/

编译opencv_cuda_第1张图片

编译opencv_cuda_第2张图片
![在这里插入图片描述](https://img-blog.csdnimg.cn/4dd076c030d640b3880e498663eed148.png?x-ossprocess=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L2t1aTk3MDI=,size_16,color_FFFFFF,t_70
编译opencv_cuda_第3张图片
这边是做java调用so库
如果出现"cannot open shared object file: No such file or directory",但是可以在系统目录下找到,则先ldd *.so,看看是不是都链接了。
如果都未链接到,如下
编译opencv_cuda_第4张图片
则做

[root@localhost libCppSurf]# export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:(你的目录,比如)/usr/local/lib64
[root@localhost libCppSurf]# ldd libSurfMatch_CUDA.so
# 则可以看到都链接到库了

编译opencv_cuda_第5张图片

之后仍然报上述"No such file or directory"的错误,则需要修改

[root@localhost libCppSurf]# vim /etc/ld.so.conf

添加如下
include /etc/ld.so.conf.d/*.conf
/usr/local/lib64(你的目录,比如)

[root@localhost libCppSurf]# sudo ldconfig

看看是否能成功

补充:
如果编译过程出现EIGEN问题 建议直接屏蔽该文件或者文件夹 主要是centos下升级gcc太折磨人 如果不是必要的,还是直接删除或者屏蔽

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