一、Opencv环境变量配置
1.计算机->属性->高级系统设置->环境变量界面;
2.在用户变量新建OPENCV 和 PATH,
OPENCV=D:\OPENCV\opencv\build ,
PATH=D:\OPENCV\opencv\build\x64\vc11\bin;D:\OPENCV\opencv\build\x86\vc11\bin 。
在系统变量的PATH里面加上D:\OPENCV\opencv\build\x64\vc11\bin;D:\OPENCV\opencv\build\x86\vc11\bin。
3.配置完以后重启电脑或者注销 环境变量才能生效。
二、进入VS进行相关目录的配置
1、新建工程:选择Win32控制台应用程序,随便取个名字即可。
2、打开项目的属性管理器,配置项目的Debug版(Release版)属性,右击Debug | Win32(Release | Win32),选择添加新项目属性表,并为即将添加的属性添加个名字。
3、在VC++目录里面修改包含目录,及库目录。
包含目录: D:\OPENCV\opencv\build\include;D:\OPENCV\opencv\build\include\opencv2;
D:\OPENCV\opencv\build\include\opencv;
库目录: D:\OPENCV\opencv\build\x86\vc11\lib;D:\OPENCV\opencv\build\x64\vc11\lib;
(注意,上面是目录所在的绝对路径,若你的软件安装在别的盘,则应该进行相应的更改)。
三、点击链接器,单击输入,修改附加依赖项。
对于Debug属性,添加如下附加依赖项:
opencv_ml249d.lib
opencv_calib3d249d.lib
opencv_contrib249d.lib
opencv_core249d.lib
opencv_features2d249d.lib
opencv_flann249d.lib
opencv_gpu249d.lib
opencv_highgui249d.lib
opencv_imgproc249d.lib
opencv_legacy249d.lib
opencv_objdetect249d.lib
opencv_ts249d.lib
opencv_video249d.lib
opencv_nonfree249d.lib
opencv_ocl249d.lib
opencv_photo249d.lib
opencv_stitching249d.lib
opencv_superres249d.lib
opencv_videostab249d.lib
对于Release属性,添加如下依赖项:
opencv_objdetect249.lib
opencv_ts249.lib
opencv_video249.lib
opencv_nonfree249.lib
opencv_ocl249.lib
opencv_photo249.lib
opencv_stitching249.lib
opencv_superres249.lib
opencv_videostab249.lib
opencv_calib3d249.lib
opencv_contrib249.lib
opencv_core249.lib
opencv_features2d249.lib
opencv_flann249.lib
opencv_gpu249.lib
opencv_highgui249.lib
opencv_imgproc249.lib
opencv_legacy249.lib
opencv_ml249.lib
然后将这两个属性保存,以后就可以直接导入就可以使用了。
四、测试程序。
#include <cv.h>
#include <highgui.h>
using namespace std;
int main()
{
IplImage * test;
test = cvLoadImage("F:\\MyFile\\2.png");//图片路径
cvNamedWindow("test_demo", 1);
cvShowImage("test_demo", test);
cvWaitKey(0);
cvDestroyWindow("test_demo");
cvReleaseImage(&test);
return 0;
}
若能成功运行此程序,则说明配置成功。