网上有很多VS2013的opencv配置教程,我也走了不少弯路。终于找到了比较好的一种方式。
VS2013和opencv3.0的下载和安装就不再累述。
以下我们从配置环境开始:
1.打开计算机的属性页,找到环境变量
2.在系统环境变量下新建下列选项
3.在系统变量中找到Path变量并在最后加上下面语句
;%OPENCV%\x86\vc12\bin
4.
在OpenCV的根目录下新建文件opencv300.props,这个文件将会在下面的VS2013配置中用到(建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>$(OPENCV)\include;$(IncludePath)</IncludePath>
<LibraryPath Condition="'$(Platform)'=='Win32'">$(OPENCV)\x86\vc12\staticlib;$(OPENCV)\x86\vc12\lib;$(LibraryPath)</LibraryPath>
<LibraryPath Condition="'$(Platform)'=='X64'">$(OPENCV)\x64\vc12\staticlib;$(OPENCV)\x64\vc12\lib;$(LibraryPath)</LibraryPath>
</PropertyGroup>
<ItemDefinitionGroup>
<Link Condition="'$(Configuration)'=='Debug'">
<AdditionalDependencies>opencv_ts300.lib;opencv_world300.lib;opencv_calib3d300.lib;opencv_core300.lib;opencv_features2d300.lib;opencv_flann300.lib;opencv_highgui300.lib;opencv_imgcodecs300.lib;opencv_imgproc300.lib;opencv_ml300.lib;opencv_objdetect300.lib;opencv_photo300.lib;opencv_shape300.lib;opencv_stitching300.lib;opencv_superres300.lib;opencv_ts300.lib;opencv_video300.lib;opencv_videoio300.lib;opencv_videostab300.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
<Link Condition="'$(Configuration)'=='Release'">
<AdditionalDependencies>opencv_ts300d.lib;opencv_world300d.lib;opencv_calib3d300d.lib;opencv_core300d.lib;opencv_features2d300d.lib;opencv_flann300d.lib;opencv_highgui300d.lib;opencv_imgcodecs300d.lib;opencv_imgproc300d.lib;opencv_ml300d.lib;opencv_objdetect300d.lib;opencv_photo300d.lib;opencv_shape300d.lib;opencv_stitching300d.lib;opencv_superres300d.lib;opencv_ts300d.lib;opencv_video300d.lib;opencv_videoio300d.lib;opencv_videostab300d.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemGroup />
</Project>
文件内容如下图
5:打开VS2013,新建一个空的Win32 控制台应用程序,工程名为OpencvTest
6:选择菜单栏中的“视图”——“属性管理器”——右击项目“添加现有属性”
7:添加现有属性成功后如下图所示
8:
然后测试代码
打开摄像头:
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/core/core.hpp>
using namespace cv;
int main()
{
VideoCapture cap(0);
Mat frame;
while (1)
{
cap >> frame;
imshow("调用摄像头", frame);
waitKey(30);
}
return 0;
}
9.如果成功那就大功告成啦啦啦![大笑](http://static.blog.csdn.net/xheditor/xheditor_emot/default/laugh.gif)
![大笑](http://static.blog.csdn.net/xheditor/xheditor_emot/default/laugh.gif)
![大笑](http://static.blog.csdn.net/xheditor/xheditor_emot/default/laugh.gif)