ubuntu-编译安装支持CUDA的OpenCV

终端运行

cmake-gui

配置源码

点击"configure"按钮,会显示很多配置项:

对于以上出现的错误项,事先下载好,配置再.cache文件夹下即可,


同时事先下载好opencv的第三方库extra。继续点击“configure”按钮:

如果需要Python编译,就修改一些Python编译的选项。

 以上红色信息是由OPENVB_GENERATE_STATUS该选项勾选造成的,可以去掉,也可以忽略。可以勾选掉java等选项,继续点击"configure",

可以配置OpenCV的Python编译环境、安装路径 prefix等,点击”configure“按钮, 

 直到需要的选项,没有出现红色的行为止:

然后点击 "Generate"按钮,即可。

这时候进入build路径,启动终端,点击”make“,

 

 编译过程中,有可能会出现以下错误:

这是因为在编译过程中,有可能环境变量没有配置完成:

配置环境变量的方法有两种,

一种是在/etc/profile文件中,配置LD_LIBRARY_PATH的值。

/usr/local/cuda-10.1/lib64:
/usr/local/opencv/lib:
/lib/x86_64-linux-gnu:
/usr/lib/x86_64-linux-gnu:
/home/pytorch/anaconda3/lib:

特别要注意/lib/x86_64-linux-gnu 和 /usr/lib/x86_64-linux-gnu,

如果需要python编译,而环境是由Anaconda环境搭建,那么一定要配置/home/pytorch/anaconda3/lib

一种是配置/etc/ld.so.conf,然后利用命令 ldconfig,将其缓存到/etc/ld.so.cache中去。

 

记录一些细节:

1:出现的红色提示信息,可以通过去掉 OPENCV_GENERATE_SETUPVARS的勾选框,默认是勾选的,

去掉勾选框即可:

2:有必要生成 OPENVB_GENERATE_PKGCONFIG,这样就可以使用PKG_CONFIG命令了,勾选此选项:

3:出现了一下错误:

/home/pytorch/anaconda3/lib/libpng16.so.16: undefined reference to `inflateValidate@ZLIB_1.2.9'
collect2: error: ld returned 1 exit status
modules/world/CMakeFiles/opencv_perf_superres.dir/build.make:124: recipe for target 'bin/opencv_perf_superres' failed
make[2]: *** [bin/opencv_perf_superres] Error 1
CMakeFiles/Makefile2:2744: recipe for target 'modules/world/CMakeFiles/opencv_perf_superres.dir/all' failed
make[1]: *** [modules/world/CMakeFiles/opencv_perf_superres.dir/all] Error 2
Makefile:160: recipe for target 'all' failed
make: *** [all] Error 2
(base) pytorch@pytorch-MS-7C22:~/Gram/softWare/opencv-4.3.0-build$ pip install --upgrade libpng
Collecting libpng
  ERROR: Could not find a version that satisfies the requirement libpng (from versions: none)
ERROR: No matching distribution found for libpng
(base) pytorch@pytorch-MS-7C22:~/Gram/softWare/opencv-4.3.0-build$ pip install libpng
Collecting libpng
  ERROR: Could not find a version that satisfies the requirement libpng (from versions: none)
ERROR: No matching distribution found for libpng
(base) pytorch@pytorch-MS-7C22:~/Gram/softWare/opencv-4.3.0-build$ pip install l(base) pytorch@pytorch-MS-7C22:~/Gram/softWare/opencv-4.3.0-build$ sudo apt-get install libpng16-16
[sudo] password for pytorch: 
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following packages were automatically installed and are no longer required:
  fonts-mathjax javascript-common libboost-python1.58.0 libboost-thread1.58.0
  libcublas7.5 libcudart7.5 libcufft7.5 libcufftw7.5 libcuinj64-7.5
  libcurand7.5 libcusolver7.5 libcusparse7.5 libjs-jquery libjs-mathjax
  libjs-sphinxdoc libjs-underscore liblapack3 libnppc7.5 libnppi7.5 libnpps7.5
  libnvblas7.5 libnvrtc7.5 libnvtoolsext1 libnvvm3 libthrust-dev libvdpau-dev
  nvidia-cuda-doc nvidia-cuda-gdb nvidia-opencl-dev nvidia-profiler
  nvidia-visual-profiler opencl-headers python-pycuda-doc python3-appdirs
  python3-decorator python3-numpy python3-pytools
Use 'sudo apt autoremove' to remove them.
The following NEW packages will be installed:
  libpng16-16
0 upgraded, 1 newly installed, 0 to remove and 1 not upgraded.
Need to get 172 kB of archives.
After this operation, 415 kB of additional disk space will be used.
Get:1 http://cn.archive.ubuntu.com/ubuntu xenial/universe amd64 libpng16-16 amd64 1.6.20-2 [172 kB]
Fetched 172 kB in 1s (100 kB/s)                        
Selecting previously unselected package libpng16-16:amd64.
(Reading database ... 251701 files and directories currently installed.)
Preparing to unpack .../libpng16-16_1.6.20-2_amd64.deb ...
Unpacking libpng16-16:amd64 (1.6.20-2) ...
Processing triggers for libc-bin (2.23-0ubuntu11) ...
/sbin/ldconfig.real: /usr/local/cuda-10.1/targets/x86_64-linux/lib/libcudnn.so.7 is not a symbolic link

Processing triggers for doc-base (0.10.7) ...
Processing 1 added doc-base file...
Setting up libpng16-16:amd64 (1.6.20-2) ...
Processing triggers for libc-bin (2.23-0ubuntu11) ...
/sbin/ldconfig.real: /usr/local/cuda-10.1/targets/x86_64-linux/lib/libcudnn.so.7 is not a symbolic link

解决方法:

 在终端输入

sudo apt-get install libpng16-16

重新进行

make

然后顺利编译通过

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值