1下载openCV,
https://sourceforge.net/projects/opencvlibrary/files/opencv-win/
参考官网https://docs.opencv.org/master/d3/d52/tutorial_windows_install.html
本次以2.4.10为例,解压到D:\opencv2.4.10
2配置环境变量
D:\opencv2.4.10\build\x86\vc11
对应关系如图
3包含路径设置
视图-〉属性管理器-〉debug处右键属性-〉通用属性-〉vc++目录-〉包含目录
添加
D:\Program Files\opencv\build\include
D:\Program Files\opencv\build\include\opencv
D:\Program Files\opencv\build\include\opencv2 这三个目录。
4库目录设置
视图-〉属性管理器-〉debug处右键属性-〉通用属性-〉vc++目录-〉库目录
添加
D:\opencv2.4.10\build\x86\vc11\lib
5链接文件设置
D:\opencv2.4.10\build\x86\vc11\lib下19*2个lib文件添加
opencv_calib3d2410d.lib
opencv_contrib2410d.lib
opencv_core2410d.lib
opencv_features2d2410d.lib
opencv_flann2410d.lib
opencv_gpu2410d.lib
opencv_highgui2410d.lib
opencv_imgproc2410d.lib
opencv_legacy2410d.lib
opencv_ml2410d.lib
opencv_nonfree2410d.lib
opencv_objdetect2410d.lib
opencv_ocl2410d.lib
opencv_photo2410d.lib
opencv_stitching2410d.lib
opencv_superres2410d.lib
opencv_ts2410d.lib
opencv_video2410d.lib
opencv_videostab2410d.lib
opencv_calib3d2410.lib
opencv_contrib2410.lib
opencv_core2410.lib
opencv_features2d2410.lib
opencv_flann2410.lib
opencv_gpu2410.lib
opencv_highgui2410.lib
opencv_imgproc2410.lib
opencv_legacy2410.lib
opencv_ml2410.lib
opencv_nonfree2410.lib
opencv_objdetect2410.lib
opencv_ocl2410.lib
opencv_photo2410.lib
opencv_stitching2410.lib
opencv_superres2410.lib
opencv_ts2410.lib
opencv_video2410.lib
opencv_videostab2410.lib
6动态链接文件
从D:\opencv2.4.10\build\x86\vc11\bin 把所有dll文件拷贝到
c:\Windows\System32(win操作系统是32位)
C:\Windows\SysWOW64(win操作系统是64位)
7测试代码
#include <opencv2\core\core.hpp>
#include <opencv2\highgui\highgui.hpp>
using namespace cv;
Mat img(300, 300, CV_8UC3);
img.setTo(Scalar(0, 255));
imshow(" Hello", img);
waitKey();
// 读入一张图片 放在cpp同目录下 或 image_dir='D:\\Docum
Mat img=imread("sample/1.jpg");
if (img.data !=NULL)
{
// 在窗口中显示
imshow("first img",img);
}