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 屬性表配置