1.首先配置环境变量,在环境变量的PATH中添加以下路径,注意路径为你解压的opencv,我这里解压到D盘的
D:\opencv\build\x86\vc10\bin;D:\opencv\build\x64\vc10\bin;
2.打开vs软件,新建一个空项目,我取名testOpenCV,右键点击项目名,选择属性,获得属性卡(或者通过以下步骤获取属性卡:项目->textOpenCV属性)
3.点击属性卡上的配置属性,选择VC++目录,
在可执行文件目录添加如下路径(注意VS版本不同,路径下的vc10不同,我的是vs2010):
D:\opencv\build\x86\vc10
在包含目录添加如下三个路径:
D:\opencv\build\include
D:\opencv\build\include\opencv
D:\opencv\build\include\opencv2
在库目录添加如下路径:
D:\opencv\build\x86\vc10\lib
4.在属性卡中点击链接器--输入--附加依赖项,在附加依赖项中加入如下内容
opencv_contrib2410d.lib
opencv_stitching2410d.lib
opencv_videostab2410d.lib
opencv_nonfree2410d.lib
opencv_superres2410d.lib
opencv_gpu2410d.lib
opencv_ocl2410d.lib
opencv_legacy2410d.lib
opencv_calib3d2410d.lib
opencv_ts2410d.lib
opencv_features2d2410d.lib
opencv_objdetect2410d.lib
opencv_highgui2410d.lib
opencv_video2410d.lib
opencv_photo2410d.lib
opencv_imgproc2410d.lib
opencv_flann2410d.lib
opencv_ml2410d.lib
opencv_core2410d.lib
opencv_contrib2410.lib
opencv_stitching2410.lib
opencv_nonfree2410.lib
opencv_superres2410.lib
opencv_videostab2410.lib
opencv_ocl2410.lib
opencv_gpu2410.lib
opencv_legacy2410.lib
opencv_calib3d2410.lib
opencv_ts2410.lib
opencv_features2d2410.lib
opencv_objdetect2410.lib
opencv_highgui2410.lib
opencv_video2410.lib
opencv_photo2410.lib
opencv_imgproc2410.lib
opencv_ml2410.lib
opencv_flann2410.lib
opencv_core2410.lib
5.点击确定,关闭属性卡,至此在VS配置OpenCV已经完成
6.在testOpenCV项目中,新建一个cpp文件,测试配置是否成功,测试代码如下
#include "highgui.h"
#include "cv.h"
#include "stdio.h"
int main(int argc,char** argv)
{
IplImage* img = cvLoadImage("test.jpg");
cvNamedWindow("图片",CV_WINDOW_FREERATIO);
cvShowImage("图片",img);
cvWaitKey(0);
cvReleaseImage(&img);
cvDestroyWindow("图片");
return 0;
}
如果能显示图片,证明你的已经成功配置opencv了