一、前期准备工作:
(1)、下载Opencv4.0.1;
https://opencv.org/releases.html
(2)、下载opencv4.0.1扩展模块(Opencv_contrib-4.0.1);
https://github.com/opencv/opencv_contrib/releases
(3)、下载Cmake3.13;
https://cmake.org/files/LatestRelease/
(4)、将Opencv4.0.1解压到指定盘(F:\Opencv4.0.1);
(5)、将opencv4.0.1扩展模块解压到指定盘(F:\Opencv_contrib-4.0.1);
(6)、将Cmake3.13解压到指定盘(F:\Cmake3.13);
ps:我用的VS是2015版的;
二、开始Cmake编译;
(1)、打开Cmake软件,开始配置;
(2)、添加Opencv源码的存放位置--》选择Cmake编译后文件保存的位置--》配置
(3)、选择安装的VS的版本--》点击finish--》等待配置完成;
(4)、勾选掉不想编译的选项(比如,我勾选掉 python3 --》点击Generate,等待编译完成;
(5)、找到OPENCV_EXTER_MODULES_PATH,添加opencv扩展模块的路径,并勾选OPENCV_ENABLE_NONFREE选项(PS:Opencv4.0.x以后的版本一定要勾选)--》点击Configure;
(6)、点击Generate,等待完成;
(7)、找到编译生成的文件夹,双击OpenCV.sln;
(8)、找到CMakeTargets--》右击INSTALL--》点击生成,等待完成,然后关闭VS;
(9)、找到install这个文件夹,这个是我们最终想要的(其他的都是多余文件,我把多余的文件删除了,并且我把install里面的文件全部复制出来重新命名,如下图),然后查看生成的lib(路径:Opencv_Compile\x64\vc14\lib);
三、配置Opencv运行环境;
(1)、打开VS,新建项目,步骤如下:
(2)、点击Debugx64-->添加新项目属性表;
(3)、设置属性表的名称-->添加;
(4)、右击Opencv_New_Debug-->属性;
(5)、VC++目录-->包含目录-->编辑;
添加完毕;
(7)、VC++目录-->库目录-->编辑
添加完毕;
(8)、链接器-->输入-->附加依赖项-->编辑;
附加依赖项(Debug版本):
opencv_xphoto401d.lib
opencv_xobjdetect401d.lib
opencv_ximgproc401d.lib
opencv_xfeatures2d401d.lib
opencv_videostab401d.lib
opencv_videoio401d.lib
opencv_video401d.lib
opencv_tracking401d.lib
opencv_text401d.lib
opencv_surface_matching401d.lib
opencv_superres401d.lib
opencv_structured_light401d.lib
opencv_stitching401d.lib
opencv_stereo401d.lib
opencv_shape401d.lib
opencv_saliency401d.lib
opencv_rgbd401d.lib
opencv_reg401d.lib
opencv_plot401d.lib
opencv_photo401d.lib
opencv_phase_unwrapping401d.lib
opencv_optflow401d.lib
opencv_line_descriptor401d.lib
opencv_imgproc401d.lib
opencv_imgcodecs401d.lib
opencv_img_hash401d.lib
opencv_highgui401d.lib
opencv_hfs401d.lib
opencv_fuzzy401d.lib
opencv_flann401d.lib
opencv_features2d401d.lib
opencv_face401d.lib
opencv_dpm401d.lib
opencv_dnn401d.lib
opencv_dnn_objdetect401d.lib
opencv_datasets401d.lib
opencv_core401d.lib
opencv_ccalib401d.lib
opencv_calib3d401d.lib
opencv_bioinspired401d.lib
opencv_bgsegm401d.lib
opencv_aruco401d.lib
opencv_objdetect401d.lib
opencv_ml401d.lib
添加完毕;
四、配置系统环境变量;
(1)、找到计算机的系统属性-->高级-->环境变量;
(2)、点击系统变量中的Path-->编辑;
(3)、点击新建-->浏览添加路径;
(4)、添加完成的路径(如图);
五、测试;
(1)、源文件-->添加-->新建项;
(2)Visual C++-->C++文件-->项目名称
(3)、Debug-->X64-->添加测试代码;
(4)、测试结果;
PS:Release版本的配置,请参考:https://blog.csdn.net/weixin_41923658/article/details/86634111
附加依赖项(Release版本):
opencv_xphoto401.lib
opencv_xobjdetect401.lib
opencv_ximgproc401.lib
opencv_xfeatures2d401.lib
opencv_videostab401.lib
opencv_videoio401.lib
opencv_video401.lib
opencv_tracking401.lib
opencv_text401.lib
opencv_surface_matching401.lib
opencv_superres401.lib
opencv_structured_light401.lib
opencv_stitching401.lib
opencv_stereo401.lib
opencv_shape401.lib
opencv_saliency401.lib
opencv_rgbd401.lib
opencv_reg401.lib
opencv_plot401.lib
opencv_photo401.lib
opencv_phase_unwrapping401.lib
opencv_optflow401.lib
opencv_line_descriptor401.lib
opencv_imgproc401.lib
opencv_imgcodecs401.lib
opencv_img_hash401.lib
opencv_highgui401.lib
opencv_hfs401.lib
opencv_fuzzy401.lib
opencv_flann401.lib
opencv_features2d401.lib
opencv_face401.lib
opencv_dpm401.lib
opencv_dnn401.lib
opencv_dnn_objdetect401.lib
opencv_datasets401.lib
opencv_core401.lib
opencv_ccalib401.lib
opencv_calib3d401.lib
opencv_bioinspired401.lib
opencv_bgsegm401.lib
opencv_aruco401.lib
opencv_objdetect401.lib
opencv_ml401.lib
扫码关注微信公众号,欢迎技术交流,其中含有大量免费的人工智能、图像处理、IT资料: