OpenCV3.3: http://opencv.org/releases.html 下载源文件
CMake:https://cmake.org/download/ 我下载的是3.9.2版本64位
contrib:https://github.com/opencv/opencv_contrib/tree/3.3.0
下载完成后解压OpenCV3.3和contrib到D:\openCV (路径可以自己决定) ,安装CMake
打开刚刚安装的CMake
按照图中的序号进行
1.选取opencv3.3的解压文件,我的是D:\openCV\opencv-3.3.0
2新建一个文件存放opencv编译后的文件,我的是D:\openCV\OpenCV
3.在第三步中选取“visual studio 15 2017 Win64”,然后确定即可。
然后等将近十分钟或者更慢,当完成之后将contrib的解压文件中的modules文件路径填到如下图所示的位置(我填的路径是D:\openCV\opencv_contrib-3.3.0\modules)
然后点击Generate即可。
稍等。。。。。。
常见错误:
1.Error in configuration process, project files may be invalid
解决办法:
出现以上错误的原因是:路径问题,我们应该使用后面的...来选择路径。
你会发现通过Windows的复制黏贴的路径是以\开始,而通过软件选择的是以/开始,注意区别。
完成之后,到刚刚新建的文件夹中,我的是D:\openCV\OpenCV
在其中用VS2017的方式打开OPENCV.sln
如上图右键“解决方案”选择重新生成解决方案
稍等。。。。。。
上一步完成后,右键INSTALL,选择“仅用于项目”,选择“仅生成INSTALL”
opencv编译好了,但由于在Release环境下所以生成的是仅用于Release环境的DLL文件,如果想在Debug模式下使用,需要在在VS下将Release改成Debug,然后重复在VS2017的步骤,这样就生成了可以在Debug模式下使用的DLL文件了。
VS2017配置opencv3.3并配置
打开小娜,查找“系统环境”点击“编辑系统环境变量”
如上图,点击“环境变量”
如上图,选择“系统变量”中的“Path”编辑
如上图,添加编译后生成的opencv文件中install文件的x64\vc15\bin文件路径,我的如图。
添加完后,重启计算机,使环境生效。
打开VS2017,
文件–>新建–>项目
选择“Windows控制台应用程序”
解决方案配置为debug(或Release),解决方案平台为x64
项目–>属性–>VC++目录–>包含目录
如上图,添加编译后在OpenCV目录中生成的install\include的路径 。 我的如图
在点击“库目录”,添加编译后在OpenCV中生成的install\x64\vc15\lib的目录。我的是 D:\openCV\OpenCV\install\x64\vc15\lib
完成后,点击右栏的“连接器”–>”输入”–>添加左栏的”附加依赖项”
Debug下,附加依赖项:
opencv_aruco330d.lib
opencv_bgsegm330d.lib
opencv_bioinspired330d.lib
opencv_calib3d330d.lib
opencv_ccalib330d.lib
opencv_core330d.lib
opencv_datasets330d.lib
opencv_dnn330d.lib
opencv_dpm330d.lib
opencv_face330d.lib
opencv_features2d330d.lib
opencv_flann330d.lib
opencv_fuzzy330d.lib
opencv_highgui330d.lib
opencv_img_hash330d.lib
opencv_imgcodecs330d.lib
opencv_imgproc330d.lib
opencv_line_descriptor330d.lib
opencv_ml330d.lib
opencv_objdetect330d.lib
opencv_optflow330d.lib
opencv_phase_unwrapping330d.lib
opencv_photo330d.lib
opencv_plot330d.lib
opencv_reg330d.lib
opencv_rgbd330d.lib
opencv_saliency330d.lib
opencv_shape330d.lib
opencv_stereo330d.lib
opencv_stitching330d.lib
opencv_structured_light330d.lib
opencv_superres330d.lib
opencv_surface_matching330d.lib
opencv_text330d.lib
opencv_tracking330d.lib
opencv_video330d.lib
opencv_videoio330d.lib
opencv_videostab330d.lib
opencv_viz330d.lib
opencv_xfeatures2d330d.lib
opencv_ximgproc330d.lib
opencv_xobjdetect330d.lib
opencv_xphoto330d.lib
Release下,附加依赖项;
opencv_aruco330.lib
opencv_bgsegm330.lib
opencv_bioinspired330.lib
opencv_calib3d330.lib
opencv_ccalib330.lib
opencv_core330.lib
opencv_datasets330.lib
opencv_dnn330.lib
opencv_dpm330.lib
opencv_face330.lib
opencv_features2d330.lib
opencv_flann330.lib
opencv_fuzzy330.lib
opencv_highgui330.lib
opencv_img_hash330.lib
opencv_imgcodecs330.lib
opencv_imgproc330.lib
opencv_line_descriptor330.lib
opencv_ml330.lib
opencv_objdetect330.lib
opencv_optflow330.lib
opencv_phase_unwrapping330.lib
opencv_photo330.lib
opencv_plot330.lib
opencv_reg330.lib
opencv_rgbd330.lib
opencv_saliency330.lib
opencv_shape330.lib
opencv_stereo330.lib
opencv_stitching330.lib
opencv_structured_light330.lib
opencv_superres330.lib
opencv_surface_matching330.lib
opencv_text330.lib
opencv_tracking330.lib
opencv_video330.lib
opencv_videoio330.lib
opencv_videostab330.lib
opencv_viz330.lib
opencv_xfeatures2d330.lib
opencv_ximgproc330.lib
opencv_xobjdetect330.lib
opencv_xphoto330.lib
程序测试:
#include <opencv2/opencv.hpp>
using namespace cv;
int main()
{
Mat img = imread("2.jpg");
imshow("1",img);
waitKey(0);
//getchar();
return 0;
}
将一幅图片放入有main.c文件的文件夹中,重命名为“2.jpg”
运行!
结果:
完成!