OpenCV+VS2013 属性表配置
Posted mfmdaoyou
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了OpenCV+VS2013 属性表配置相关的知识,希望对你有一定的参考价值。
简单介绍
计算机视觉任务越来越多的依赖著名的开源计算机视觉库OpenCV。
OpenCV 2.0 包括了一系列精心设计数据结构和经过优化的视觉算法。大家能够短时间内开发一个不错的视觉应用。OpenCV支持多种不同的硬件和软件平台。这也是它被广泛应用的一个重要原因。使用C/C++开发OpenCV程序,须要告知编译器、连接器对应的头文件文件夹、库文件以库文件的文件夹,在开发不同的项目的时候。每次都分别指定这三项内容操作起来有些麻烦,本文针对OpenCV+VS2013介绍一种通过加入属性表和合并调试环境变量的方式来简化配置过程。
本文測试过的详细情况有:
OpenCV Version | Configuration | Platform |
---|---|---|
2.4.10 | Debug, Release | x64, Win32 |
2.4.11 | Debug, Release | x64, Win32 |
2.4.12 | Debug, Release | x64, Win32 |
3.0.0 | Debug, Release | x64, Win32 |
准备OpenCV
在OpenCV的官方站点下载对应的版本号(这里測试过2.4.10。2.4.11,2.4.12,3.0.0四个版本号)。下载完毕后,双击对应的exe文件,它会自解压到你指定的文件夹下。
在解压后的文件夹下找到build文件夹,将此文件夹下的全部内容复制到某个固定的文件夹下。以后的开发都会引用这个文件夹,所以最好谨慎选择存放位置。
比如我将OpenCV2.4.10的build文件夹的全部内容存放在K:\OpenCV\2.4.10
这个文件夹下,(后面的配置过程都将以此文件夹为例),
将x64和x86两个文件夹下的vc12、vc11和vc10分别改成vc12.0、vc11.0和vc10.0
属性表
以2.4.10为例。新建一个文本文件,将其重命名为”OpenCV_2.4.10.props”(不要带引號)。
用记事本编辑,拷贝例如以下内容:
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ImportGroup Label="PropertySheets" />
<PropertyGroup>
<IncludePath>K:\OpenCV\2.4.10\include\opencv;K:\OpenCV\2.4.10\include;$(IncludePath)</IncludePath>
<LibraryPath>K:\OpenCV\2.4.10\$(PlatformShortName)\vc$(VisualStudioVersion)\lib;$(LibraryPath)</LibraryPath>
</PropertyGroup>
<ItemDefinitionGroup>
<Link Condition="‘$(Configuration)‘==‘Debug‘">
<AdditionalDependencies>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_ml2410d.lib;opencv_nonfree2410d.lib;opencv_objdetect2410d.lib;opencv_ocl2410d.lib;opencv_photo2410d.lib;opencv_stitching2410d.lib;opencv_superres2410d.lib;opencv_ts2410d.lib;opencv_video2410d.lib;opencv_videostab2410d.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
<Link Condition="‘$(Configuration)‘==‘Release‘">
<AdditionalDependencies>opencv_calib3d2410.lib;opencv_contrib2410.lib;opencv_core2410.lib;opencv_features2d2410.lib;opencv_flann2410.lib;opencv_gpu2410.lib;opencv_highgui2410.lib;opencv_imgproc2410.lib;opencv_legacy2410.lib;opencv_ml2410.lib;opencv_nonfree2410.lib;opencv_objdetect2410.lib;opencv_ocl2410.lib;opencv_photo2410.lib;opencv_stitching2410.lib;opencv_superres2410.lib;opencv_ts2410.lib;opencv_video2410.lib;opencv_videostab2410.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
</Project>
保存OpenCV_2.4.10.props之后,将文件关闭。
project配置
新建一个Win32 控制台project(Win32 Console Application)。在属性管理器中加入刚才保存的属性表。全部不同配置能够使用同一个属性表,由于属性表对全部情况做了处理。
注意:假设属性表和project在同一个分区下。那么project文件会使用相对路径。
这样一来,拷贝project到不同的文件夹后。project就不能被正确载入了。所以,建议将属性表放到某个特定的分区,project文件夹最好跟属性表不要在同一个分区。
运行编译后程序
编译成功后,可能会提示某某dll找不到。将以下的内容复制到project的“属性–> 调试 –> 环境”。
PATH=K:\OpenCV\2.4.10\$(PlatformShortName)\vc$(VisualStudioVersion)\bin;$(PATH) $(LocalDebuggerEnvironment)
附加:其它几个版本号的属性表
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ImportGroup Label="PropertySheets" />
<PropertyGroup>
<IncludePath>K:\OpenCV\2.4.11\include\opencv;K:\OpenCV\2.4.11\include;$(IncludePath)</IncludePath>
<LibraryPath>K:\OpenCV\2.4.11\$(PlatformShortName)\vc$(VisualStudioVersion)\lib;$(LibraryPath)</LibraryPath>
</PropertyGroup>
<ItemDefinitionGroup>
<Link Condition="‘$(Configuration)‘==‘Debug‘">
<AdditionalDependencies>opencv_calib3d2411d.lib;opencv_contrib2411d.lib;opencv_core2411d.lib;opencv_features2d2411d.lib;opencv_flann2411d.lib;opencv_gpu2411d.lib;opencv_highgui2411d.lib;opencv_imgproc2411d.lib;opencv_legacy2411d.lib;opencv_ml2411d.lib;opencv_nonfree2411d.lib;opencv_objdetect2411d.lib;opencv_ocl2411d.lib;opencv_photo2411d.lib;opencv_stitching2411d.lib;opencv_superres2411d.lib;opencv_ts2411d.lib;opencv_video2411d.lib;opencv_videostab2411d.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
<Link Condition="‘$(Configuration)‘==‘Release‘">
<AdditionalDependencies>opencv_calib3d2411.lib;opencv_contrib2411.lib;opencv_core2411.lib;opencv_features2d2411.lib;opencv_flann2411.lib;opencv_gpu2411.lib;opencv_highgui2411.lib;opencv_imgproc2411.lib;opencv_legacy2411.lib;opencv_ml2411.lib;opencv_nonfree2411.lib;opencv_objdetect2411.lib;opencv_ocl2411.lib;opencv_photo2411.lib;opencv_stitching2411.lib;opencv_superres2411.lib;opencv_ts2411.lib;opencv_video2411.lib;opencv_videostab2411.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
</Project>
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ImportGroup Label="PropertySheets" />
<PropertyGroup>
<IncludePath>K:\OpenCV\2.4.12\include\opencv;K:\OpenCV\2.4.12\include;$(IncludePath)</IncludePath>
<LibraryPath>K:\OpenCV\2.4.12\$(PlatformShortName)\vc$(VisualStudioVersion)\lib;$(LibraryPath)</LibraryPath>
</PropertyGroup>
<ItemDefinitionGroup>
<Link Condition="‘$(Configuration)‘==‘Debug‘">
<AdditionalDependencies>opencv_calib3d2412d.lib;opencv_contrib2412d.lib;opencv_core2412d.lib;opencv_features2d2412d.lib;opencv_flann2412d.lib;opencv_gpu2412d.lib;opencv_highgui2412d.lib;opencv_imgproc2412d.lib;opencv_legacy2412d.lib;opencv_ml2412d.lib;opencv_nonfree2412d.lib;opencv_objdetect2412d.lib;opencv_ocl2412d.lib;opencv_photo2412d.lib;opencv_stitching2412d.lib;opencv_superres2412d.lib;opencv_ts2412d.lib;opencv_video2412d.lib;opencv_videostab2412d.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
<Link Condition="‘$(Configuration)‘==‘Release‘">
<AdditionalDependencies>opencv_calib3d2412.lib;opencv_contrib2412.lib;opencv_core2412.lib;opencv_features2d2412.lib;opencv_flann2412.lib;opencv_gpu2412.lib;opencv_highgui2412.lib;opencv_imgproc2412.lib;opencv_legacy2412.lib;opencv_ml2412.lib;opencv_nonfree2412.lib;opencv_objdetect2412.lib;opencv_ocl2412.lib;opencv_photo2412.lib;opencv_stitching2412.lib;opencv_superres2412.lib;opencv_ts2412.lib;opencv_video2412.lib;opencv_videostab2412.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
</Project>
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ImportGroup Label="PropertySheets" />
<PropertyGroup>
<IncludePath>K:\OpenCV\3.0.0\include\opencv;K:\OpenCV\3.0.0\include;$(IncludePath)</IncludePath>
<LibraryPath>K:\OpenCV\3.0.0\$(PlatformShortName)\vc$(VisualStudioVersion)\lib;$(LibraryPath)</LibraryPath>
</PropertyGroup>
<ItemDefinitionGroup>
<Link Condition="‘$(Configuration)‘==‘Debug‘">
<AdditionalDependencies>opencv_ts300d.lib;opencv_world300d.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
<Link Condition="‘$(Configuration)‘==‘Release‘">
<AdditionalDependencies>opencv_ts300.lib;opencv_world300.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
</Project>
測试程序project及代码
注意:必须改动对应项目中的属性表路径,否则不能用!
注意:属性表要换成你自己的,就是路径要跟你自己的硬盘上对应的路径对应好。否则不能用!
http://pan.baidu.com/s/1i43Pflr
以上是关于OpenCV+VS2013 属性表配置的主要内容,如果未能解决你的问题,请参考以下文章