- 在C:\Users\账号名\AppData\Local\Microsoft\MSBuild\v4.0找到Microsoft.Cpp.Win32.user.props
- 在该地址中下载文件替换原有的Microsoft.Cpp.Win32.user.props
下面为替换后Microsoft.Cpp.Win32.user.props的内容:
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ImportGroup Label="PropertySheets">
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup>
<IncludePath>D:\Program Files (x86)\opencv\build\include;D:\Program Files (x86)\opencv\build\include\opencv;D:\Program Files (x86)\opencv\build\include\opencv2;$(IncludePath)</IncludePath>
<LibraryPath>D:\Program Files (x86)\opencv\build\x86\vc12\lib;$(LibraryPath)</LibraryPath>
<ExecutablePath>D:\Program Files (x86)\opencv\build\x86\vc12\bin;$(ExecutablePath)</ExecutablePath>
</PropertyGroup>
<ItemDefinitionGroup>
<ClCompile>
<MultiProcessorCompilation>true</MultiProcessorCompilation>
</ClCompile>
<Link>
<AdditionalLibraryDirectories>$(Platform)</AdditionalLibraryDirectories>
<AdditionalDependencies>opencv_ts300d.lib;opencv_world300d.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemGroup />
</Project>
- 将<IncludePath>,<LibraryPath>,<ExecutablePath>这三行的中的D:\Program Files (x86)\opencv改为你的opencv文件位置;
- 若你的为vs为2012版的,则将<LibraryPath>,<ExecutablePath>这两行中的vc12改为vc11;
- 倒数第五行添加lib文件名,lib文件名可以参考opencv\build\x86\vc12\lib里的文件名
- 将对应的opencv的路径,如D:\Program Files (x86)\opencv\build\include;D:\Program Files (x86)\opencv\build\x86\vc12\lib;D:\Program Files (x86)\opencv\build\x86\vc12\bin;添加到系统的PATH
- 最后保存即可
新建vs项目,测试代码为:
<span style="font-size:18px;">#include "highgui.h"
#include "stdio.h"
using namespace cv;
int main()
{
IplImage* img = cvLoadImage("test.jpg");
if (img == NULL)
{
printf("fail to load image\n");
exit(-1);
}
cvShowImage("test", img);
cvWaitKey(0);
cvReleaseImage(&img);
cvDestroyAllWindows();
return 0;
}</span>