如果VS先前已经配置过opencv,
进入文件夹:C:\Users\randongmei\AppData\Local\Microsoft\MSBuild\v4.0,打开Microsoft.Cpp.x64.user或Microsoft.Cpp.Win32.user文件
删除opencv相关的配置即可。
opencv下载地址 :https://github.com/opencv/opencv/releases
下载Source code不要下载.exe,cmake编译时需要source code中cmakeList.txt,如果没有会报错。
opencv contrlib下载地址:https://github.com/opencv/opencv_contrib/releases
cmake官网下载,https://cmake.org/download/
下载msi文件,双击就可以安装,安装时注意选择添加路径到环境变量和创建桌面按钮。
VS2015
链接:https://pan.baidu.com/s/1ckwI05Sm7QSNujTFCLVeyQ
密码:lx7q
下载后解压,双击vs_community.exe安装,注意安装的时候自定义安装,只选择visual C++其他的都不选。
解压下载的opencv源码opencv-3.4.0.zip和opencv附加包opencv_contrib-3.4.0.zip,将解压的文件包放在同一路径下,我这里放在D:\\盘。
设置编译路径
where is the source code:opencv源码opencv-3.4.0.zip解压包中CMakeList.txt所在路径
where is the build the binaries:opencv编译后放置的路径。
编译opencv3.4.0
点击【configure】按钮
编译opencv_contrib-3.4.0
编译完opencv3.4.0后中间出现许多列表,下拉列表,找到OPENCV_EXTRA_MODULES_PATH,选择opencv_contrib中modules所在路径D:\opencv_contrib-3.4.0\opencv_contrib-3.4.0\modules,然后再次点击【configure】按钮,操作与编译opencv3.4.0相同。
生成代码,点击【generate】按钮
where is the build the binaries中选择的路径中找到opencv.sln,双击该文件,点击【Build】检查是否能编译成功。
一般情况下都能编译成功,成功后,选择 CMakeTargets下的INSTALL右键选择仅用于项目->仅生成INSTALL即可,之后会在where is the build the binaries中选择的路径中找到一个install文件夹
配置opencv的环境变量
在计算机-环境变量-path中增加:where to build the binaries中设置的路径\install\x64\vc14\bin
针对如何自动生成动态库列表,写了一个小工具,有兴趣的可以参考:VS2010配置opencv2.4.10+查找小工具生成lib文件名列表
一共有39个动态库:
release版本,
opencv_aruco340.lib
opencv_bgsegm340.lib
opencv_bioinspired340.lib
opencv_calib3d340.lib
opencv_ccalib340.lib
opencv_core340.lib
opencv_datasets340.lib
opencv_dnn340.lib
opencv_dpm340.lib
opencv_face340.lib
opencv_features2d340.lib
opencv_flann340.lib
opencv_fuzzy340.lib
opencv_highgui340.lib
opencv_imgcodecs340.lib
opencv_imgproc340.lib
opencv_img_hash340.lib
opencv_line_descriptor340.lib
opencv_ml340.lib
opencv_objdetect340.lib
opencv_optflow340.lib
opencv_phase_unwrapping340.lib
opencv_photo340.lib
opencv_plot340.lib
opencv_reg340.lib
opencv_rgbd340.lib
opencv_saliency340.lib
opencv_shape340.lib
opencv_stereo340.lib
opencv_stitching340.lib
opencv_structured_light340.lib
opencv_superres340.lib
opencv_surface_matching340.lib
opencv_text340.lib
opencv_tracking340.lib
opencv_video340.lib
opencv_videoio340.lib
opencv_videostab340.lib
opencv_xfeatures2d340.lib
opencv_ximgproc340.lib
opencv_xobjdetect340.lib
opencv_xphoto340.lib
debug版本:
opencv_aruco340d.lib
opencv_bgsegm340d.lib
opencv_bioinspired340d.lib
opencv_calib3d340d.lib
opencv_ccalib340d.lib
opencv_core340d.lib
opencv_datasets340d.lib
opencv_dnn340d.lib
opencv_dpm340d.lib
opencv_face340d.lib
opencv_features2d340d.lib
opencv_flann340d.lib
opencv_fuzzy340d.lib
opencv_highgui340d.lib
opencv_imgcodecs340d.lib
opencv_imgproc340d.lib
opencv_img_hash340d.lib
opencv_line_descriptor340d.lib
opencv_ml340d.lib
opencv_objdetect340d.lib
opencv_optflow340d.lib
opencv_phase_unwrapping340d.lib
opencv_photo340d.lib
opencv_plot340d.lib
opencv_reg340d.lib
opencv_rgbd340d.lib
opencv_saliency340d.lib
opencv_shape340d.lib
opencv_stereo340d.lib
opencv_stitching340d.lib
opencv_structured_light340d.lib
opencv_superres340d.lib
opencv_surface_matching340d.lib
opencv_text340d.lib
opencv_tracking340d.lib
opencv_video340d.lib
opencv_videoio340d.lib
opencv_videostab340d.lib
opencv_xfeatures2d340d.lib
opencv_ximgproc340d.lib
opencv_xobjdetect340d.lib
opencv_xphoto340d.lib
参考文献:
https://elody-07.github.io/opencv3.4.1+contrib+cmake3.11.0/
https://blog.csdn.net/qq_37791134/article/details/80739395