前两天配置OpenCV,每建一个工程都要手动配置一些东西,觉得太麻烦了,后来查到vs可以使用属性表配置属性,研究了一下,弄了下面一个属性表,内容如下:
文件名:opencv.props(使用OpenCV2.4.3)
<?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> <EmbedManifest>false</EmbedManifest> <IncludePath>$(OPENCV)\include\opencv2;$(OPENCV)\include\opencv;$(OPENCV)\include;$(IncludePath)</IncludePath> <LibraryPath Condition="'$(Platform)'=='Win32'">$(OPENCV)\x86\vc10\lib;$(LibraryPath)</LibraryPath> <LibraryPath Condition="'$(Platform)'=='X64'">$(OPENCV)\x64\vc10\lib;$(LibraryPath)</LibraryPath> </PropertyGroup> <ItemDefinitionGroup> <Link Condition="'$(Configuration)'=='Debug'"> <AdditionalDependencies>opencv_legacy243d.lib;opencv_calib3d243d.lib;opencv_contrib243d.lib;opencv_core243d.lib;opencv_features2d243d.lib;opencv_flann243d.lib;opencv_gpu243d.lib;opencv_highgui243d.lib;opencv_imgproc243d.lib;opencv_legacy243d.lib;opencv_ml243d.lib;opencv_nonfree243d.lib;opencv_objdetect243d.lib;opencv_photo243d.lib;opencv_stitching243d.lib;opencv_ts243d.lib;opencv_video243d.lib;opencv_videostab243d.lib;%(AdditionalDependencies)</AdditionalDependencies> </Link> <Link Condition="'$(Configuration)'=='Release'"> <AdditionalDependencies>opencv_legacy243.lib;opencv_calib3d243.lib;opencv_contrib243.lib;opencv_core243.lib;opencv_features2d243.lib;opencv_flann243.lib;opencv_gpu243.lib;opencv_highgui243.lib;opencv_imgproc243.lib;opencv_legacy243.lib;opencv_ml243.lib;opencv_nonfree243.lib;opencv_objdetect243.lib;opencv_photo243.lib;opencv_stitching243.lib;opencv_ts243.lib;opencv_video243.lib;opencv_videostab243.lib;%(AdditionalDependencies)</AdditionalDependencies> </Link> </ItemDefinitionGroup> <ItemGroup /> </Project>
使用方法:
1.设置环境变量,详见本博客另一篇博文:VS2010 + OpenCV2.4.3的配置步骤
2.建立工程,在属性管理器中右击项目名称-->添加现有属性表,选择opencv.props就ok了
如何修改:
1.OpenCV版本不同:本例使用的OpenCV版本是2.4.3,对应lib库的末尾是243,其他版本相应修改即可
2.VS版本不同:vc10代表vs2010,其他版本相应修改:VC8(2005), VC9(2008), VC10(2010),
VC11(2012), VC12(2013)
3.目标编译平台不同:本例为vs默认的win32平台(win7的32位和64位都可以用),如果项目非要选x64的话,需要改两个地方:
(1) 环境变量的路径改为x64(如 D:\OpenCV243\build\x64\vc10\bin)
(2)去掉配置表中的这一行:
<LibraryPath Condition="'$(Platform)'=='Win32'">$(OPENCV)\x86\vc10\lib;$(LibraryPath)</LibraryPath>
时间: 2024-10-26 15:29:23