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

OpenCV 3.0+ VS2013开发环境基本配置已在前文“OpenCV3.0+VS2013配置一”中进行了介绍,有些时候我们可能需要重复配置相同的环境,相信大家都会采用一些自动化的手段,这里总结一下我自己自动化配置的方法。

一、环境变量
新建OpenCV3.0_Environment_Win7.txt,编辑内容如下:


@echo on 
  
:: 设置第三方库环境变量OpenCV
wmic ENVIRONMENT create name="OPENCV",username="",VariableValue="D:\opencv3.0\build"  
echo %ENVIRONMENT create successfully%  
  
wmic ENVIRONMENT where "name='path' and username=''" 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 ^ >"%msbuild_config_home%\Microsoft.Cpp.Win32.user.props"
echo ^ >>"%msbuild_config_home%\Microsoft.Cpp.Win32.user.props"


echo ^  >>"%msbuild_config_home%\Microsoft.Cpp.Win32.user.props"
echo  ^ >>"%msbuild_config_home%\Microsoft.Cpp.Win32.user.props"

echo ^  >>"%msbuild_config_home%\Microsoft.Cpp.Win32.user.props"
echo  ^ >>"%msbuild_config_home%\Microsoft.Cpp.Win32.user.props"

::IncludePath
echo  ^ >>"%msbuild_config_home%\Microsoft.Cpp.Win32.user.props"
echo    ^$(VCInstallDir)include;$(VCInstallDir)atlmfc\include;$(WindowsSdkDir)include;$(FrameworkSDKDir)\include;C:\Program Files (x86)\Microsoft SDKs\Windows\v7.1A\Include^ >>"%msbuild_config_home%\Microsoft.Cpp.Win32.user.props"
echo  ^ >>"%msbuild_config_home%\Microsoft.Cpp.Win32.user.props"

::IncludePath_OpenCV3.0
echo  ^ >>"%msbuild_config_home%\Microsoft.Cpp.Win32.user.props"
echo    ^E:\opencv3.0\build\include\opencv2;E:\opencv3.0\build\include\opencv;E:\opencv3.0\build\include;$(IncludePath)^ >>"%msbuild_config_home%\Microsoft.Cpp.Win32.user.props"
echo  ^ >>"%msbuild_config_home%\Microsoft.Cpp.Win32.user.props"

::LibraryPath
echo  ^ >>"%msbuild_config_home%\Microsoft.Cpp.Win32.user.props"
echo    ^$(VCInstallDir)lib;$(VCInstallDir)atlmfc\lib;$(WindowsSdkDir)lib;$(FrameworkSDKDir)\lib;C:\Program Files (x86)\Microsoft SDKs\Windows\v7.1A\Lib^ >>"%msbuild_config_home%\Microsoft.Cpp.Win32.user.props"
echo  ^ >>"%msbuild_config_home%\Microsoft.Cpp.Win32.user.props"

::LibraryPath_OpenCV3.0
echo  ^ >>"%msbuild_config_home%\Microsoft.Cpp.Win32.user.props"
echo    ^E:\opencv3.0\build\x86\vc12\lib;E:\opencv3.0\build\x86\vc12\staticlib;$(LibraryPath)^ >>"%msbuild_config_home%\Microsoft.Cpp.Win32.user.props"
echo  ^ >>"%msbuild_config_home%\Microsoft.Cpp.Win32.user.props"

echo  ^ >>"%msbuild_config_home%\Microsoft.Cpp.Win32.user.props"
echo    ^ >>"%msbuild_config_home%\Microsoft.Cpp.Win32.user.props"
::AdditionalDependencies_Debug_OpenCV3.0
echo      ^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)^ >>"%msbuild_config_home%\Microsoft.Cpp.Win32.user.props"
echo    ^ >>"%msbuild_config_home%\Microsoft.Cpp.Win32.user.props"
echo    ^ >>"%msbuild_config_home%\Microsoft.Cpp.Win32.user.props"
::AdditionalDependencies_Release_OpenCV3.0
echo      ^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)^ >>"%msbuild_config_home%\Microsoft.Cpp.Win32.user.props"
echo    ^ >>"%msbuild_config_home%\Microsoft.Cpp.Win32.user.props"
echo  ^ >>"%msbuild_config_home%\Microsoft.Cpp.Win32.user.props"


echo ^ >>"%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两份文件,如果需要换一台电脑再次进行配置时,只需要分别运行两个命令行脚本即可轻松完成配置!

你可能感兴趣的:(OpenCV)