1. 安装Visual Studio Ultimate 2013
2. 下载OpenCV for Windows, http://opencv.org/downloads.html
3. 解压到 D:\Program Files (x86) 目录
4. 设置环境变量PATH, 值为:D:\Program Files (x86)\opencv\build\x86\vc12\bin;D:\Program Files (x86)\opencv\build\x64\vc12\bin
5. 添加include目录: Properties-->Configuration Properties-->C/C++-->General-->Additional Include Directories-->D:\Program Files (x86)\opencv\build\include
6. 添加lib目录: Properties-->Configuration Properties-->Linker-->General-->Additional Library Directories-->D:\Program Files (x86)\opencv\build\x64\vc12\lib
7. 添加代码中导入相关的头文件和库文件, 如下:
#include "stdafx.h"
#include
#ifdef _DEBUG
#pragma comment(lib,"opencv_core2413d.lib")
#pragma comment(lib,"opencv_highgui2413d.lib")
#pragma comment(lib,"opencv_calib3d2413d.lib")
#pragma comment(lib,"opencv_contrib2413d.lib")
#pragma comment(lib,"opencv_features2d2413d.lib")
#pragma comment(lib,"opencv_flann2413d.lib")
#pragma comment(lib,"opencv_gpu2413d.lib")
#pragma comment(lib,"opencv_imgproc2413d.lib")
#pragma comment(lib,"opencv_legacy2413d.lib")
#pragma comment(lib,"opencv_ml2413d.lib")
#pragma comment(lib,"opencv_objdetect2413d.lib")
#pragma comment(lib,"opencv_ts2413d.lib")
#pragma comment(lib,"opencv_video2413d.lib")
#else
#pragma comment(lib,"opencv_core2413.lib")
#pragma comment(lib,"opencv_highgui2413.lib")
#pragma comment(lib,"opencv_calib3d2413.lib")
#pragma comment(lib,"opencv_contrib2413.lib")
#pragma comment(lib,"opencv_features2d2413.lib")
#pragma comment(lib,"opencv_flann2413.lib")
#pragma comment(lib,"opencv_gpu2413.lib")
#pragma comment(lib,"opencv_imgproc2413.lib")
#pragma comment(lib,"opencv_legacy2413.lib")
#pragma comment(lib,"opencv_ml2413.lib")
#pragma comment(lib,"opencv_objdetect2413.lib")
#pragma comment(lib,"opencv_ts2413.lib")
#pragma comment(lib,"opencv_video2413.lib")
#endif
using namespace std;
using namespace cv;
void main()
{
const char* imagename = "opencv_test.jpg";//调试时当前路径为源码根目录,运行时为当前exe相同目录
Mat img = imread(imagename);
if(img.empty())
{
fprintf(stderr, "Can not load image %s\n", imagename);
return;
}
imshow("image", img);
waitKey();
return;
}
OpenCV中文网: http://wiki.opencv.org.cn/index.php/Download