1.首先下载好相应版本的vs和opencv
(1)opencv官网地址:
https://sourceforge.net/p/opencvlibrary/activity/?page=0&limit=100#5fe1e00044ac957958f9e218
注:找到opencv2.4.9版本点击下载,注意选择与自己系统对应的下载包(如windows系统、ios系统、linux系统等)
(2)vs2013获取地址:
链接:https://pan.baidu.com/s/1wAiMB_IU0bNMU18iQHHUKA
提取码:ngyp
注:opencv2.4.9的安装包网盘里也有
2.进行opencv环境配置:
"计算机"上右击选择属性->高级->环境变量
(1)用户变量配置:
在用户变量中新建一个opencv的变量值,添加opencv的build路径;
(2)系统变量配置:
找到系统变量中的PATH,编辑,在末尾添加
例如 ;D:\Program Files\opencv\build\x86\vc12\bin
注:如没有PATH,需要新建,若是有,就在末尾添加;并且将添加的路径复制进去即可
并且,环境配置之后需重启计算机才能生效,配置到此步骤,然后重启计算机
3.进行VS2013环境配置:
(1)新建一个项目:文件->新建->项目
点击下一步
选择空项目
不选选项四
右击源文件,新建一个.cpp文件,如test.cpp文件
注:VS中一个项目只能有一个包含main函数的源文件,
若要某项目中有多个源文件,参考https://blog.csdn.net/qq_30815237/article/details/87452311
(2)视图->属性页/项目->属性
需要配置的有:可执行文件目录、包含目录、库目录
最右边选择
下拉编辑
然后,附加依赖项的配置:
输入下面的链接库名:
opencv_calib3d249d.lib
opencv_contrib249d.lib
opencv_core249d.lib
opencv_features2d249d.lib
opencv_flann249d.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
opencv_nonfree249.lib
opencv_objdetect249.lib
opencv_photo249.lib
opencv_stitching249.lib
opencv_ts249.lib
opencv_video249.lib
opencv_videostab249.lib
opencv_gpu249d.lib
opencv_highgui249d.lib
opencv_imgproc249d.lib
opencv_legacy249d.lib
opencv_ml249d.lib
opencv_nonfree249d.lib
opencv_objdetect249d.lib
opencv_photo249d.lib
opencv_stitching249d.lib
opencv_ts249d.lib
opencv_video249d.lib
opencv_videostab249d.lib
注:以上均是在debug模式下配置的,即
或
下
注意:一般在配置工程时,Debug工程的“链接器->附加依赖项”一般只加d.lib库;而Release工程的“链接器->附加依赖项”一般只加.lib库,这样就可以避免采用imread读取图片报错的情况。
参考:https://blog.csdn.net/xzq413520903/article/details/87932637
接下来要配置release版的,主要区别在于不带d:
输入下面的链接库名:
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
配置到此就完成了,接下来测试是否配置成功
4.环境配置好之后的代码测试:
新建一个test.cpp文件,将以下一段代码运行,看是否能输出图片:
#include <cv.h>
#include <highgui.h>
using namespace std;
int main()
{
IplImage * test;
test = cvLoadImage(“D:\demo1.jpg”);//图片路径
cvNamedWindow(“test_demo”, 1);
cvShowImage(“test_demo”, test);
cvWaitKey(0);
cvDestroyWindow(“test_demo”);
cvReleaseImage(&test);
return 0;
}
成功的结果如下图所示:
以上教程参考:https://blog.csdn.net/lyq_12/article/details/84326659
https://jingyan.baidu.com/article/75ab0bcbee4b47d6864db2fc.html