opencv2.4.10與VS2013的環境配置

前言html

項目幾乎都是圖像相關的,通常都會用到opencv開源庫,就涉及到windows下opencv的環境配置問題,本文對此進行介紹。c++

環境windows

系統環境:win10_x64(其餘windows系統相似);ide

opencv版本:2.4.10(其餘版本相似);測試

VS版本:VS2013;ui

實現步驟spa

1.下載安裝opencv開源庫;.net

2.配置環境變量;debug

3.配置項目屬性;3d

4.測試工程;

操做過程

1.下載安裝opencv開源庫;

下載對應版本的opencv源here,解壓到某一目錄便可,最好的是固定的,這樣能夠一樣應用於其餘工程的配置;

博主的目錄是D:\lib\OpenCV\opencv2410,也是方便將全部可能用到的庫安裝在一個固定的路徑。

2.配置環境變量;

2.1 打開win10的設置信息的系統一欄,關於 -> 系統信息 -> 高級系統設置 -> 環境變量;

2.2 用戶變量一欄,新建用戶變量以下,注意變量值要根據本身的安裝目錄進行修改;

2.3 系統變量一欄,點擊path進行編輯以下圖所示,注意目錄按安裝目錄進行修改;

2.4 到此環境變量配置完畢。重啓電腦或註銷電腦,使環境變量生效。

注意,其餘系統可能與win10的配置過程有些微不一樣,但大體都同樣的。

3.配置項目屬性;

3.1 編輯opencv工程屬性表;

新建兩個文件opencvdebug.props和opencvrelease.props,分別表示debug和release版本工程的opencv屬性表,

主要內容含有工程使用opencv的c++目錄中的包含目錄和附加依賴項,後續還須要在工程中添加opencv的庫目錄;

opencvdebug.props

<?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>
    <IncludePath>D:\lib\OpenCV\opencv2410\build\include;D:\lib\OpenCV\opencv2410\build\include\opencv;D:\lib\OpenCV\opencv2410\build\include\opencv2;$(IncludePath)</IncludePath>
    <LibraryPath>$(LibraryPath)</LibraryPath>
  </PropertyGroup>
  <ItemDefinitionGroup>
    <Link>
      <AdditionalDependencies>opencv_ml2410d.lib;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_objdetect2410d.lib;opencv_ts2410d.lib;opencv_video2410d.lib;opencv_nonfree2410d.lib;opencv_ocl2410d.lib;opencv_photo2410d.lib;opencv_stitching2410d.lib;opencv_superres2410d.lib;opencv_videostab2410d.lib;%(AdditionalDependencies)</AdditionalDependencies>
    </Link>
  </ItemDefinitionGroup>
  <ItemGroup />
</Project>

opencvrelease.props

<?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>
    <IncludePath>D:\lib\OpenCV\opencv2410\build\include;D:\lib\OpenCV\opencv2410\build\include\opencv;D:\lib\OpenCV\opencv2410\build\include\opencv2;$(IncludePath)</IncludePath>
    <LibraryPath>$(LibraryPath)</LibraryPath>
  </PropertyGroup>
  <ItemDefinitionGroup>
    <Link>
      <AdditionalDependencies>opencv_objdetect2410.lib;opencv_ts2410.lib;opencv_video2410.lib;opencv_nonfree2410.lib;opencv_ocl2410.lib;opencv_photo2410.lib;opencv_stitching2410.lib;opencv_superres2410.lib;opencv_videostab2410.lib;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;%(AdditionalDependencies)</AdditionalDependencies>
    </Link>
  </ItemDefinitionGroup>
  <ItemGroup />
</Project>

注意,屬性表中的路徑是對應的安裝路徑,另外,也能夠以其餘方式進行配置,詳見參考部分;

3.2 將屬性表分別調價到工程的屬性管理器中;

屬性管理器的打開方式,視圖 -> 其餘窗口 -> 屬性管理器;

3.3 在項目屬性的VC++目錄的庫目錄中添加工程的庫目錄,D:\lib\OpenCV\opencv2410\build\x64\vc12\lib;

注意,全部屬性的配置都須要在debug和release版本分別進行配置,這樣兩個版本的才均可以正常運行;

4.測試工程;

新建工程,按照以上步驟配置環境和項目屬性,測試代碼以下,可以正常運行即測試成功。

#include<cv.h> #include<highgui.h>
int main(int argc, char** argv[]) { IplImage* src = cvLoadImage("lena.jpg", CV_LOAD_IMAGE_GRAYSCALE); cvNamedWindow("Src", CV_WINDOW_AUTOSIZE); cvShowImage("Src", src); cvWaitKey(0); cvReleaseImage(&src); cvDestroyAllWindows(); return 0; }

問題及注意事項

1.注意工程的平臺是win32仍是x64的;

2.注意須要對應工程的debug和release版本;

3.各類目錄都須要對應準確;

參考

1.opencv配置

2.百度百科的介紹

3.完美配置攻略

相關文章
相關標籤/搜索