OpenCV3.1.0下载地址:https://opencv.org/releases/
找到OpenCV3.1.0下载Windows版本,下载完成后双击解压
将D:\opencv3.1.0\opencv\build\x64\vc14\bin文件夹下的3个.dll文件复制放入文件夹C:\Windows\System32和C:\Windows\SysWOW64下即可
OpenCV_contrib下载地址https://github.com/opencv/opencv_contrib/releases
找到版本3.1.0选择zip格式下载,下载完后在文件夹中解压
CUDA8.0下载地址:https://developer.nvidia.com/cuda-80-ga2-download-archive
选择network在后续安装中会自动根据需求联网下载所需的包,local即安装前一次性下完所有的东西,笔者推荐选择前者,选择后者出现过与VS2015匹配失败的问题,需要手动处理非常麻烦。
下载完成直接运行:
在这个窗口之前的系统检查可以会提示存在更高版本的残留导致部分功能不可用,无视即可。选择精简模式,安装路径也按照默认路径安装。
安装完成后在C:\ProgramData\NVIDIA Corporation\CUDA Samples\v8.0文件夹下找到Sample_vs2015.sln,双击加载退出。然后验证是否配置成功。
在cmd下输入nvcc -V,若没有出现下图则重新安装吧:
进一步检查CUDA安装的正确性
C:\ProgramData\NVIDIA Corporation\CUDASamples\v8.0\1_Utilities\deviceQuery文件夹下的deviceQuery_vs2015.sln程序,编译运行会显示显卡信息
出现上图则说明CUDA8.0配置成功。
CMake下载地址:https://github.com/Kitware/CMake/releases
CMake的版本一定要是3.4.3,不可以更高,否则会出现非常非常多的问题,比如
无法打开输入文件“…\lib\Release\opencv_bioinspired310.lib”
估计是OpenCV没有对CMake的高版本做相应的更改。
下载完成后双击安装,注意下图选择
这样便可自动添加环境变量了。
安装完成后重启打开cmd,输入cmake,显示下图信息即表示安装成功:
CMake编辑OpenCV
运行CMake,新建一空文件夹opencv_build来存放生成的文件
选择源文件夹及生成文件夹,源文件夹为OpenCV解压文件夹下的sources文件夹
点击Configure
选择Win64,点击Finish.
中途会出现诸如此类的错误:
这是因为坑爹的OpenCV3.1.0源码cmake需要额外下载opencv_ffmpeg.dll、opencv_ffmpeg_64.dll,、ffmpeg_version.cmake以及ippicv_windows_20151201.zip,笔者在这里分享相关文件:
链接:https://pan.baidu.com/s/1nrwUUJsTHwP7L9dVwFA0EA
提取码:tmff
每当报出类似错误就找对应的文件及文件夹替换进去即可。
完成后出现下图:
第一次全红,再次点击Configure,这次变为全白
勾选选项with_cuda,在OPENCV_EXTRA_MODULES_PATH中选择路径
D:/opencv3.1.0/opencv_contrib310/modules,即opencv_contrib下的modules
再次点击Configure,同样第一次全红,然后再次点击第二次全白。
出现Configuring done后点击Generate即完成生成。
生成库
在D:\opencv3.1.0\opencv_build文件夹中找到OpenCV.sln,双击加载
加载完成后在Debug模式下选择重新生成解决方案,该过程大概需要2-3个小时
中途如果弹出外部环境发生变化点击全部重新加载
生成完成后可能会出现不少项目错误,这可能导致部分库不能使用,放过它吧
右键INSTALL–>仅用于项目–>仅生成INSTALL(B)
然后选择Realse,重新生成解决方案进行同样的操作。
完成后D:\opencv3.1.0\opencv_build\install\x64\vc14\lib文件夹下生成lib文件
将路径D:\opencv3.1.0\opencv_build\install\x64\vc14\lib添加入环境变量中
至此便完成了所有的生成工作了
VS2015中新建win32控制台应用程序
配置Dubug
在项目属性中,选择配置Debug,平台x64
VC++目录添加包含目录
D:\opencv3.1.0\opencv_buildcuda\install\include
D:\opencv3.1.0\opencv_buildcuda\install\include\opencv
D:\opencv3.1.0\opencv_buildcuda\install\include\opencv2
添加库目录
D:\opencv3.1.0\opencv_buildcuda\install\x64\vc14\lib
C/C++附加包含目录
D:\opencv3.1.0\opencv_buildcuda\install\include
D:\opencv3.1.0\opencv_buildcuda\install\include\opencv
D:\opencv3.1.0\opencv_buildcuda\install\include\opencv2
链接器–>常规添加附加库目录
D:\opencv3.1.0\opencv_buildcuda\install\x64\vc14\lib
链接器->输入添加附加依赖项
opencv_aruco310d.lib
opencv_bgsegm310d.lib
opencv_bioinspired310d.lib
opencv_calib3d310d.lib
opencv_ccalib310d.lib
opencv_core310d.lib
opencv_cudaarithm310d.lib
opencv_cudabgsegm310d.lib
opencv_cudacodec310d.lib
opencv_cudafeatures2d310d.lib
opencv_cudafilters310d.lib
opencv_cudaimgproc310d.lib
opencv_cudastereo310d.lib
opencv_cudawarping310d.lib
opencv_cudev310d.lib
opencv_datasets310d.lib
opencv_dnn310d.lib
opencv_dpm310d.lib
opencv_face310d.lib
opencv_features2d310d.lib
opencv_flann310d.lib
opencv_fuzzy310d.lib
opencv_highgui310d.lib
opencv_imgcodecs310d.lib
opencv_imgproc310d.lib
opencv_line_descriptor310d.lib
opencv_ml310d.lib
opencv_objdetect310d.lib
opencv_optflow310d.lib
opencv_photo310d.lib
opencv_plot310d.lib
opencv_reg310d.lib
opencv_rgbd310d.lib
opencv_saliency310d.lib
opencv_shape310d.lib
opencv_stereo310d.lib
opencv_structured_light310d.lib
opencv_surface_matching310d.lib
opencv_text310d.lib
opencv_tracking310d.lib
opencv_ts310d.lib
opencv_video310d.lib
opencv_videoio310d.lib
opencv_xfeatures2d310d.lib
opencv_ximgproc310d.lib
opencv_xobjdetect310d.lib
opencv_xphoto310d.lib
注意附加依赖项每个人不同,这个即是文件夹D:\opencv3.1.0\opencv_build\install\x64\vc14\lib
中所有的lib文件
配置Release
Release中的配置与Debug下基本相同,唯一不同的便是附加依赖项中文件换为
opencv_aruco310.lib
opencv_bgsegm310.lib
opencv_bioinspired310.lib
opencv_calib3d310.lib
opencv_ccalib310.lib
opencv_core310.lib
opencv_cudaarithm310.lib
opencv_cudabgsegm310.lib
opencv_cudacodec310.lib
opencv_cudafeatures2d310.lib
opencv_cudafilters310.lib
opencv_cudaimgproc310.lib
opencv_cudastereo310.lib
opencv_cudawarping310.lib
opencv_cudev310.lib
opencv_datasets310.lib
opencv_dnn310.lib
opencv_dpm310.lib
opencv_face310.lib
opencv_features2d310.lib
opencv_flann310.lib
opencv_fuzzy310.lib
opencv_highgui310.lib
opencv_imgcodecs310.lib
opencv_imgproc310.lib
opencv_line_descriptor310.lib
opencv_ml310.lib
opencv_objdetect310.lib
opencv_optflow310.lib
opencv_photo310.lib
opencv_plot310.lib
opencv_reg310.lib
opencv_rgbd310.lib
opencv_saliency310.lib
opencv_shape310.lib
opencv_stereo310.lib
opencv_structured_light310.lib
opencv_surface_matching310.lib
opencv_text310.lib
opencv_tracking310.lib
opencv_ts310.lib
opencv_video310.lib
opencv_videoio310.lib
opencv_xfeatures2d310.lib
opencv_ximgproc310.lib
opencv_xobjdetect310.lib
opencv_xphoto310.lib
VS2015配置OpenCV+CUDA完成
下面用opencv源码中的例子拿出来测试:
代码在: opencv-master\samples\cpp\tutorial_code\gpu\gpu-basics-similarity\gpu-basics-similarity.cpp文件夹中,
将此代码复制到刚刚建的控制台应用程序中,然后点击生成。
将生成的.exe文件拖入cmd控制台,输入参数
OpenCV_CUDAtest.exe left.jpg right.jpg 10
Reference:
https://blog.csdn.net/u011231598/article/details/80338941
https://blog.csdn.net/leilonghit/article/details/81460704
https://blog.csdn.net/clover_my/article/details/89521568
https://my.oschina.net/u/3919756/blog/1935291
https://www.cnblogs.com/asmer-stone/p/5530868.html
https://www.jianshu.com/p/3ec3f690015c
https://blog.csdn.net/ezhchai/article/details/80557936
https://www.cnblogs.com/Yan47/articles/5967537.html
https://download.csdn.net/download/panda1234lee/9656265
https://blog.csdn.net/stjuliet/article/details/83957512
https://blog.csdn.net/qq_15947787/article/details/78534272
https://www.cnblogs.com/arxive/p/11198420.html