配置方法包括各类每次新建项目需要进行配置的方法和一次性配置的方法。
1.版本
opencv:2.4.10 下载地址:
http://opencv.org/downloads.html
visual stdio:2013
系统:windows7 64位
2.安装
vs2013安装不做说明,opencv下载完成后直接点击安装,界面如下:
安装路径确定后进行安装,生成opencv文件夹,包含build和sources两个文件夹。
3.配置
参考链接如下:
3.1配置opencv环境变量
依次点开:计算机-属性-高级系统设置-高级-环境变量。
在用户变量栏添加用户变量path,变量值为对应vs版本的动态链接库文件目录,如D:\opencv\build\x86\vc12\bin,重启电脑生效。
3.2配置vs2013环境
3.2.1在项目属性中进行配置
【注】此种方法需要每次新建项目时进行如下配置
(1)配置属性-VS++目录-包含目录,进行如下添加:
D:\software\opencv2.4.10\opencv\build\include
D:\software\opencv2.4.10\opencv\build\include\opencv
D:\software\opencv2.4.10\opencv\build\include\opencv2
D:\software\opencv2.4.10\opencv\build\include\opencv
D:\software\opencv2.4.10\opencv\build\include\opencv2
(2)配置属性-VS++目录-库目录,进行如下添加:
D:\software\opencv2.4.10\opencv\build\x86\vc12\lib
(3)链接器-输入-附加依赖项。若在debug环境下运行则进行如下添加:
opencv_nonfree2410d.lib
opencv_legacy2410d.lib
opencv_features2d2410d.lib
opencv_calib3d2410d.lib
opencv_contrib2410d.lib
opencv_core2410d.lib
opencv_flann2410d.lib
opencv_gpu2410d.lib
opencv_highgui2410d.lib
opencv_imgproc2410d.lib
opencv_ml2410d.lib
opencv_objdetect2410d.lib
opencv_ts2410d.lib
opencv_video2410d.lib
opencv_legacy2410d.lib
opencv_features2d2410d.lib
opencv_calib3d2410d.lib
opencv_contrib2410d.lib
opencv_core2410d.lib
opencv_flann2410d.lib
opencv_gpu2410d.lib
opencv_highgui2410d.lib
opencv_imgproc2410d.lib
opencv_ml2410d.lib
opencv_objdetect2410d.lib
opencv_ts2410d.lib
opencv_video2410d.lib
这里2410即为版本号,d对应debug配置,若使用release,则将以上d去掉即可。
3步完成后便完成配置。
(4)测试配置
#include "stdafx.h"
#include "cv.h"
#include "highgui.h"
#include "cxcore.h"
using namespace cv;
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
Mat img;
img = imread("1.bmp");
imshow("Lakers",img);
waitKey(0);
return 0;
}
显示图片即为成功。
3.2.2在属性管理器中进行配置
(1)
在属性管理器下对Debug和Release版本右键属性进行配置
【注】步骤和3.2.1一致,但仍然是每次新建项目需要进行如上配置。
(2)
添加属性表
【注】每次新建项目直接添加属性表即可
对于属性表的生成有以下方法,参考链接如下:
1)
使用TXT文本生成属性表文件
创建txt文件,文件另存为opencvdebug.props
内容添加如下:
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ImportGroup Label="PropertySheets" />
<PropertyGroup Label="UserMacros" />
<PropertyGroup>
<IncludePath>D:\software\opencv2.4.10\opencv\build\include;D:\software\opencv2.4.10\opencv\build\include\opencv;D:\software\opencv2.4.10\opencv\build\include\opencv2;$(IncludePath)</IncludePath>
<LibraryPath>D:\software\opencv2.4.10\opencv\build\x86\vc12\lib;$(LibraryPath)</LibraryPath>
</PropertyGroup>
<ItemDefinitionGroup>
<Link> <AdditionalDependencies>opencv_ml2410d.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_objdetect2410d.lib;opencv_ts2410d.lib;opencv_video2410d.lib;opencv_nonfree2410d.lib;opencv_ocl2410d.lib;opencv_photo2410d.lib;opencv_stitching2410d.lib;opencv_superres2410d.lib;opencv_videostab2410d.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemGroup />
</Project>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ImportGroup Label="PropertySheets" />
<PropertyGroup Label="UserMacros" />
<PropertyGroup>
<IncludePath>D:\software\opencv2.4.10\opencv\build\include;D:\software\opencv2.4.10\opencv\build\include\opencv;D:\software\opencv2.4.10\opencv\build\include\opencv2;$(IncludePath)</IncludePath>
<LibraryPath>D:\software\opencv2.4.10\opencv\build\x86\vc12\lib;$(LibraryPath)</LibraryPath>
</PropertyGroup>
<ItemDefinitionGroup>
<Link> <AdditionalDependencies>opencv_ml2410d.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_objdetect2410d.lib;opencv_ts2410d.lib;opencv_video2410d.lib;opencv_nonfree2410d.lib;opencv_ocl2410d.lib;opencv_photo2410d.lib;opencv_stitching2410d.lib;opencv_superres2410d.lib;opencv_videostab2410d.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemGroup />
</Project>
使用时更改对应的包含引用目录和链接库即可,release版本同理。
2)
在属性管器下新建属性表
右键属性管理器的Debug|WIN32,新建属性表,右键属性表,按3.2.1进行配置,配置完后右键属性表进行保存,release版本同理。
(3)
属性管理器下的opencv永久配置
【注】该方法只需进行一次配置即可
参考如下:
属性管理器-Debug|WIN32-Microsoft.Cpp.Win32.user
右键属性同3.2.1进行配置,完成后则后续新建项目就不需要进行opencv的配置了,release版本同理。