1、下载安装Cmake:https://cmake.org/download/
(1)下载与电脑系统匹配的版本的安装包
(2)双击安装,安装过程中选择添加Cmake到环境路径中
(3)在cmd命令窗口中键入“cmake”查看是否安装成功
2、下载opencv库和opencv_contrib库
opencv_contrib-3.2.0.zip压缩包:https://github.com/opencv/opencv_contrib/releases?after=3.4.3
opencv-3.2.0.zip压缩包和opencv-3.2.0-vc14.exe:https://opencv.org/releases/page/3/
或者全部直接去Github上下载:https://github.com/opencv/opencv/tags?after=3.3.0-rc
3、编译opencv3.2
(1)新建build_64文件夹用来存放稍后生成的vs2013可编译工程,
(2)打开cmake-gui,选取路径,点击Configure,选择编译器
点击finish出现进度
此处Configure中需要联网下载ippicv与ffmepg,若没有出现Configure done,再次点击Configure,出现错误看下文第7步
(3)添加扩展库路径 OPENCV_EXTRA_MODULES_PATH = D:\opencv\opencv_contrib-3.2.0\modules
(4)点击add Entry按钮,添加CMAKE_DEBUG_POSTFIX选项,值设为“d”
这一操作用于区分debug(后缀多一个d)和release版本,否则编译安装时debug版本会被release版本覆盖
设置好后,再点击configure,如果之后还有红色的块,继续点击configure,直到没有红色的块
(5)点击Generate按钮,生成vs2013可编译工程。然后点击Open Project按钮即会自动使用vs2013打开。
4、VS2013中配置
Generate之后会在build_64目录下看到CMake生成的编译工程,用vs2013打开工程
(1)先在Release x64下编译,耗时较长(2~3小时)
右键ALL BUILD选择生成
完成后,右键INSTALL选择生成
生成的库安装在build_64文件夹下自动生成的install文件夹中
(2)在Debug x64下编译,过程与debug类似
5、添加环境变量
6、在VS2013中添加库
(1)右键工程属性在包含目录中添加include路径
(2)在库目录中添加lib路径
(3)在附加依赖项中添加库的名称
pthreadVC2.lib
cublas.lib
curand.lib
cudart.lib
opencv_world320.lib
opencv_aruco320.lib
opencv_bgsegm320.lib
opencv_bioinspired320.lib
opencv_calib3d320.lib
opencv_ccalib320.lib
opencv_core320.lib
opencv_cudaarithm320.lib
opencv_cudabgsegm320.lib
opencv_cudacodec320.lib
opencv_cudafeatures2d320.lib
opencv_cudafilters320.lib
opencv_cudaimgproc320.lib
opencv_cudalegacy320.lib
opencv_cudaobjdetect320.lib
opencv_cudaoptflow320.lib
opencv_cudastereo320.lib
opencv_cudawarping320.lib
opencv_cudev320.lib
opencv_datasets320.lib
opencv_dnn320.lib
opencv_dpm320.lib
opencv_face320.lib
opencv_features2d320.lib
opencv_flann320.lib
opencv_fuzzy320.lib
opencv_hdf320.lib
opencv_highgui320.lib
opencv_imgcodecs320.lib
opencv_imgproc320.lib
opencv_line_descriptor320.lib
opencv_ml320.lib
opencv_objdetect320.lib
opencv_optflow320.lib
opencv_phase_unwrapping320.lib
opencv_photo320.lib
opencv_plot320.lib
opencv_reg320.lib
opencv_rgbd320.lib
opencv_saliency320.lib
opencv_shape320.lib
opencv_stereo320.lib
opencv_stitching320.lib
opencv_structured_light320.lib
opencv_superres320.lib
opencv_surface_matching320.lib
opencv_text320.lib
opencv_tracking320.lib
opencv_video320.lib
opencv_videoio320.lib
opencv_videostab320.lib
opencv_xfeatures2d320.lib
opencv_ximgproc320.lib
opencv_xobjdetect320.lib
opencv_xphoto320.lib
7、错误
第3步的(2)中会自动下载opencv_ffmpeg.dll等依赖项,如果自动下载失败就会出现这类错误,可以在网络稳定的情况下重新Configure下载,或者手动下载配置,参考编译OpenCV时,ffmpeg或ippicv下载失败的解决方案。
(2)CMake Error: The following variables are used in this project, but they are set to NOTFOUND.
这是一个“Win32或x64”架构问题。由于NVIDIA只提供cufft
,nvblas
,nppc
,nppi
,npps
库为64位,CMake自然是不可能找到这些库配置一个Win32 OpenCV库。在cmake-gui中点击file -> delete cache,再点击Configure,设置编译器时如第3步(2)中图片2,一定要选择“x64”(这是由于电脑系统是64位,编译器默认32位,如果本身就是32位则不会出错不用修改)
(3)第4步中Debug x64下编译错误:fatal error LNK1104: 无法打开文件“python27_d.lib”
安装Python时没有下载debug库,找不到这个文件。安装python的debug版本,在库目录中添加python27_d.lib所在路径,在附加依赖项中添加python27_d.lib文件名
8、参考:
cmake-gui使用教程
vs2013+opencv3.2配置
【OpenCV3】OpenCV3.2.0在VS2013环境下Cmake编译与快速配置
CMake: CUDA libraries not found when compiling OpenCV
LNK1104 无法打开文件“python37_d.lib” 解决办法
VS2013下创建OpenCV项目