1. 程式人生 > >OpenCV3.0 + VS2013配置二:自動化配置

OpenCV3.0 + VS2013配置二:自動化配置

OpenCV 3.0+ VS2013開發環境基本配置已在前文“OpenCV3.0+VS2013配置一”中進行了介紹,有些時候我們可能需要重複配置相同的環境,相信大家都會採用一些自動化的手段,這裡總結一下我自己自動化配置的方法。

一、環境變數
新建OpenCV3.0_Environment_Win7.txt,編輯內容如下:


@echo on 

:: 設定第三方庫環境變數OpenCV
wmic ENVIRONMENT create name="OPENCV",username="<system>",VariableValue="D:\opencv3.0\build"  
echo %ENVIRONMENT create
successfully% wmic ENVIRONMENT where "name='path' and username='<system>'" set VariableValue="%path%;D:\opencv3.0\build\x86\vc12\bin" pause

儲存並修改後綴名為OpenCV3.0_Environment_Win7.cmd,雙擊執行後需要重啟計算機才能生效。

二、VS2013專案屬性表
新建OpenCV3.0_VS2013_Win7.txt,編輯內容如下:

@echo off

ver | findstr /M /C:"5.1"
IF
%errorlevel% == 0 ( set localappdata=%userprofile%\Local Settings\Application Data ) set msbuild_config_home=%localappdata%\Microsoft\MSBuild\v4.0 if exist "%msbuild_config_home%\Microsoft.Cpp.Win32.user.props" ( for /F "tokens=1-2 delims=: " %%i in ('time /T') do ( set ftime=%%i_%%j ) echo %ftime% for
/F "tokens=1-4 delims=-/ " %%k in ('date /T') do ( set fdate=%%k_%%l_%%m_%%n ) echo %fdate% if exist "%msbuild_config_home%\Microsoft.Cpp.Win32.user.props.%fdate%_%ftime%.bak" ( del /F /Q "%msbuild_config_home%\Microsoft.Cpp.Win32.user.props.%fdate%_%ftime%.bak" ) rename "%msbuild_config_home%\Microsoft.Cpp.Win32.user.props" "Microsoft.Cpp.Win32.user.props.%fdate%_%ftime%.bak" ) echo ^<?xml version="1.0" encoding="utf-8"?^> >"%msbuild_config_home%\Microsoft.Cpp.Win32.user.props" echo ^<Project DefaultTargets="Build" ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"^> >>"%msbuild_config_home%\Microsoft.Cpp.Win32.user.props" echo ^<ImportGroup Label="PropertySheets"^> >>"%msbuild_config_home%\Microsoft.Cpp.Win32.user.props" echo ^</ImportGroup^> >>"%msbuild_config_home%\Microsoft.Cpp.Win32.user.props" echo ^<PropertyGroup Label="UserMacros"^> >>"%msbuild_config_home%\Microsoft.Cpp.Win32.user.props" echo ^</PropertyGroup^> >>"%msbuild_config_home%\Microsoft.Cpp.Win32.user.props" ::IncludePath echo ^<PropertyGroup^> >>"%msbuild_config_home%\Microsoft.Cpp.Win32.user.props" echo ^<IncludePath^>$(VCInstallDir)include;$(VCInstallDir)atlmfc\include;$(WindowsSdkDir)include;$(FrameworkSDKDir)\include;C:\Program Files (x86)\Microsoft SDKs\Windows\v7.1A\Include^</IncludePath^> >>"%msbuild_config_home%\Microsoft.Cpp.Win32.user.props" echo ^</PropertyGroup^> >>"%msbuild_config_home%\Microsoft.Cpp.Win32.user.props" ::IncludePath_OpenCV3.0 echo ^<PropertyGroup^> >>"%msbuild_config_home%\Microsoft.Cpp.Win32.user.props" echo ^<IncludePath^>E:\opencv3.0\build\include\opencv2;E:\opencv3.0\build\include\opencv;E:\opencv3.0\build\include;$(IncludePath)^</IncludePath^> >>"%msbuild_config_home%\Microsoft.Cpp.Win32.user.props" echo ^</PropertyGroup^> >>"%msbuild_config_home%\Microsoft.Cpp.Win32.user.props" ::LibraryPath echo ^<PropertyGroup^> >>"%msbuild_config_home%\Microsoft.Cpp.Win32.user.props" echo ^<LibraryPath^>$(VCInstallDir)lib;$(VCInstallDir)atlmfc\lib;$(WindowsSdkDir)lib;$(FrameworkSDKDir)\lib;C:\Program Files (x86)\Microsoft SDKs\Windows\v7.1A\Lib^</LibraryPath^> >>"%msbuild_config_home%\Microsoft.Cpp.Win32.user.props" echo ^</PropertyGroup^> >>"%msbuild_config_home%\Microsoft.Cpp.Win32.user.props" ::LibraryPath_OpenCV3.0 echo ^<PropertyGroup^> >>"%msbuild_config_home%\Microsoft.Cpp.Win32.user.props" echo ^<LibraryPath^>E:\opencv3.0\build\x86\vc12\lib;E:\opencv3.0\build\x86\vc12\staticlib;$(LibraryPath)^</LibraryPath^> >>"%msbuild_config_home%\Microsoft.Cpp.Win32.user.props" echo ^</PropertyGroup^> >>"%msbuild_config_home%\Microsoft.Cpp.Win32.user.props" echo ^<ItemDefinitionGroup^> >>"%msbuild_config_home%\Microsoft.Cpp.Win32.user.props" echo ^<Link Condition="$(Configuration)== 'Debug'"^> >>"%msbuild_config_home%\Microsoft.Cpp.Win32.user.props" ::AdditionalDependencies_Debug_OpenCV3.0 echo ^<AdditionalDependencies^>opencv_ts300d.lib;opencv_world300d.lib;IlmImfd.lib;libjasperd.lib;libjpegd.lib;libpngd.lib;libtiffd.lib;libwebpd.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_video300d.lib;opencv_videoio300d.lib;opencv_videostab300d.lib;Zlibd.lib;$(AdditionalDependencies)^</AdditionalDependencies^> >>"%msbuild_config_home%\Microsoft.Cpp.Win32.user.props" echo ^</Link^> >>"%msbuild_config_home%\Microsoft.Cpp.Win32.user.props" echo ^<Link Condition="$(Configuration)== 'Release'"^> >>"%msbuild_config_home%\Microsoft.Cpp.Win32.user.props" ::AdditionalDependencies_Release_OpenCV3.0 echo ^<AdditionalDependencies^>opencv_ts300.lib;opencv_world300.lib;IlmImf.lib;ippicvmt.lib;libjasper.lib;libjpeg.lib;libpng.lib;libtiff.lib;libwebp.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_video300.lib;opencv_videoio300.lib;opencv_videostab300.lib;Zlib.lib;$(AdditionalDependencies)^</AdditionalDependencies^> >>"%msbuild_config_home%\Microsoft.Cpp.Win32.user.props" echo ^</Link^> >>"%msbuild_config_home%\Microsoft.Cpp.Win32.user.props" echo ^</ItemDefinitionGroup^> >>"%msbuild_config_home%\Microsoft.Cpp.Win32.user.props" echo ^</Project^> >>"%msbuild_config_home%\Microsoft.Cpp.Win32.user.props" echo OpenCV3.0 config successfully! pause

儲存後修改後綴名為.cmd,雙擊執行後提示OpenCV3.0 config successfully!完成配置。

以上配置OpenCV檔案路徑為E:\opencv3.0,可根據需要進行調整,
儲存好OpenCV3.0_Environment_Win7.cmd和OpenCV3.0_VS2013_Win7.cmd兩份檔案,如果需要換一臺電腦再次進行配置時,只需要分別執行兩個命令列指令碼即可輕鬆完成配置!