1.本地环境
cuda=9.0
python=3.6
cmake=5.6
2.安装的opencv版本=2.4.13
3.安装流程
(1)从github上下载opencv2.4.13的源码
(2)安装
unzip opencv-2.4.13.zip cd opencv-2.4.13 mkdir build cd build cmake .. make
4.出现的问题
(1)
CUDA_nppi_LIBRARY (ADVANCED) linked by target "opencv_cudev" in directory D:/Cproject/opencv/opencv/sources/modules/cudev
出现类似的这样的问题。解决方案如下:
https://blog.csdn.net/u014613745/article/details/78310916
简单记录下:
opencv2 只需执行1,2,3,5步骤,opencv3执行1,2,3,4,5步骤
1).找到FindCUDA.cmake文件
找到行
find_cuda_helper_libs(nppi)
改为
find_cuda_helper_libs(nppial)
find_cuda_helper_libs(nppicc)
find_cuda_helper_libs(nppicom)
find_cuda_helper_libs(nppidei)
find_cuda_helper_libs(nppif)
find_cuda_helper_libs(nppig)
find_cuda_helper_libs(nppim)
find_cuda_helper_libs(nppist)
find_cuda_helper_libs(nppisu)
find_cuda_helper_libs(nppitc)
2).找到行
set(CUDA_npp_LIBRARY "${CUDA_nppc_LIBRARY};${CUDA_nppi_LIBRARY};${CUDA_npps_LIBRARY}")
改为
set(CUDA_npp_LIBRARY "${CUDA_nppc_LIBRARY};${CUDA_nppial_LIBRARY};${CUDA_nppicc_LIBRARY};${CUDA_nppicom_LIBRARY};${CUDA_nppidei_LIBRARY};${CUDA_nppif_LIBRARY};${CUDA_nppig_LIBRARY};${CUDA_nppim_LIBRARY};${CUDA_nppist_LIBRARY};${CUDA_nppisu_LIBRARY};${CUDA_nppitc_LIBRARY};${CUDA_npps_LIBRARY}")
3).找到行
unset(CUDA_nppi_LIBRARY CACHE)
改为
unset(CUDA_nppial_LIBRARY CACHE)
unset(CUDA_nppicc_LIBRARY CACHE)
unset(CUDA_nppicom_LIBRARY CACHE)
unset(CUDA_nppidei_LIBRARY CACHE)
unset(CUDA_nppif_LIBRARY CACHE)
unset(CUDA_nppig_LIBRARY CACHE)
unset(CUDA_nppim_LIBRARY CACHE)
unset(CUDA_nppist_LIBRARY CACHE)
unset(CUDA_nppisu_LIBRARY CACHE)
unset(CUDA_nppitc_LIBRARY CACHE)
4).找到文件OpenCVDetectCUDA.cmake
修改以下几行
...
set(__cuda_arch_ptx "")
if(CUDA_GENERATION STREQUAL "Fermi")
set(__cuda_arch_bin "2.0")
elseif(CUDA_GENERATION STREQUAL "Kepler")
set(__cuda_arch_bin "3.0 3.5 3.7")
...
改为
...
set(__cuda_arch_ptx "")
if(CUDA_GENERATION STREQUAL "Kepler")
set(__cuda_arch_bin "3.0 3.5 3.7")
elseif(CUDA_GENERATION STREQUAL "Maxwell")
set(__cuda_arch_bin "5.0 5.2")
...
5).cuda9中有一个单独的halffloat(cuda_fp16.h)头文件,也应该被包括在opencv的目录里
将头文件cuda_fp16.h添加至 opencv\modules\cudev\include\opencv2\cudev\common.hpp
即在common.hpp中添加
#include <cuda_fp16.h>
重新生成即可
(2)Unsupported gpu architecture 'compute_20'
解决方案:https://blog.csdn.net/langb2014/article/details/51658744
简单记录下:
cmake的时候加一些参数
cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D CUDA_GENERATION=Kepler ..
这里,install_prefix感觉最好是装在这个路径,因为很多程序找opencv的时候也还是找的这个路径
(3) /usr/bin/ld: cannot find -lopencv_dep_nppial /usr/bin/ld: cannot find -lopencv_dep_nppicc /usr/bin/ld: cannot find -lopencv_dep_nppicom /usr/bin/ld: cannot find -lopencv_dep_nppidei /usr/bin/ld: cannot find -lopencv_dep_nppif /usr/bin/ld: cannot find -lopencv_dep_nppig /usr/bin/ld: cannot find -lopencv_dep_nppim /usr/bin/ld: cannot find -lopencv_dep_nppist /usr/bin/ld: cannot find -lopencv_dep_nppisu /usr/bin/ld: cannot find -lopencv_dep_nppitc collect2: error: ld returned 1 exit status make[2]: *** [extract_cpu] Error 1 make[1]: *** [CMakeFiles/extract_cpu.dir/all] Error 2 make: *** [all] Error 2
https://blog.csdn.net/liuxiao214/article/details/85201268
解决方案:添加团连接,从你所用cuda版本中找到对应为文件,进行连接即可。
ln -s /usr/local/cuda-9.2/targets/x86_64-linux/lib/libnppial.so /usr/local/lib/libopencv_dep_nppial.so
ln -s /usr/local/cuda-9.2/targets/x86_64-linux/lib/libnppicc.so /usr/local/lib/libopencv_dep_nppicc.so
ln -s /usr/local/cuda-9.2/targets/x86_64-linux/lib/libnppicom.so /usr/local/lib/libopencv_dep_nppicom.so
ln -s /usr/local/cuda-9.2/targets/x86_64-linux/lib/libnppidei.so /usr/local/lib/libopencv_dep_nppidei.so
ln -s /usr/local/cuda-9.2/targets/x86_64-linux/lib/libnppif.so /usr/local/lib/libopencv_dep_nppif.so
ln -s /usr/local/cuda-9.2/targets/x86_64-linux/lib/libnppig.so /usr/local/lib/libopencv_dep_nppig.so
ln -s /usr/local/cuda-9.2/targets/x86_64-linux/lib/libnppim.so /usr/local/lib/libopencv_dep_nppim.so
ln -s /usr/local/cuda-9.2/targets/x86_64-linux/lib/libnppist.so /usr/local/lib/libopencv_dep_nppist.so
ln -s /usr/local/cuda-9.2/targets/x86_64-linux/lib/libnppisu.so /usr/local/lib/libopencv_dep_nppisu.so
ln -s /usr/local/cuda-9.2/targets/x86_64-linux/lib/libnppitc.so /usr/local/lib/libopencv_dep_nppitc.so
ln -s /usr/local/cuda-9.0/lib64/libnppisu.so /usr/local/lib/libopencv_dep_nppisu.so
(4)libopencv_highgui.so.2.4.13: undefined reference to `TIFFReadRGBAStrip@LIBTI
opencv编译完后,在其他项目中使用opencv时,make发生以上错误。
http://www.voidcn.com/article/p-mrofikyf-mo.html
解决方案:
a.在opencv编译时,添加参数
cmake -D BUILD_TIFF=ON
b.再make,make install ,记得需要make install,不然我好像时没有效果。
(5)libQt5Widgets.so.5.6.2: undefined reference to `operator delete[](void*, unsigned long)@CXXABI_1.3.9'
在使用了opencv的项目编译时加参数:
cmake -D CMAKE_EXE_LINKER_FLAGS='-static-libstdc++ -std=c++11' ..
(6)opencv make时发生,
/usr/bin/ld: cannot find -lstdc++ 错误
https://blog.csdn.net/analogous_love/article/details/79053594
在centos中,使用static方法编译,需要安装static version of glibc-static libstdc++-static。使用如下命令安装
yum install glibc-static libstdc++-static
(7)opencv环境变量配置
https://www.cnblogs.com/qiaozhoulin/p/4978055.html
一、安装opencv(这里不再讲述)
二、添加库路径(创建opencv.conf文件)
输入命令:vi /etc/ld.so.conf.d/opencv.conf
输入/usr/local/lib,并保存退出
三、添加环境变量
输入命令:vi /etc/profile
在末尾加入:
export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig:$PKG_CONFIG_PATH
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib
更新环境变量:source /etc/profile
四、设置另外环境变量
输入命令:vi /etc/bash.bashrc
在末尾加入:
export PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib
更新环境变量:source /etc/profile
五、更新系统库缓存
输入命令:ldconfig
六、查看opencv是否安装成功
输入命令:pkg-config—cflags opencv
pkg-config—libs opencv
如果没有出错,说明安装成功。
七、测试
输入命令:(假设有个opencv_test.cpp文件实现显示图像功能)
g++ opencv_test.cpp `pkg-config --cflags --libs opencv` -o opencv_test
(说明:--cflags:指明头文件路径; --libs:指明库文件搜索路径)
然后运行:./opencv_test
(这里需要特别注意的是如果输入以下命令是不会成功的(即opencv_test.cpp放在后面)
g++ `pkg-config --cflags --libs opencv` opencv_test.cpp -o opencv_test)
(生成动态链接库可输入:gcc test.c `pkg-config --cflags --libs opencv` -fPIC -shared -o libtest.so)
出现五彩斑斓的图片,说明opencv测试成功!