VC 2008 Express下安裝OpenCV2.0/2.1









VC 2008 Express下安裝OpenCV2.0/2.1


|
0
意見
]


http://www.opencv.org.cn/index.php/VC_2008_Express%E4%B8%8B%E5%AE%89%E8%A3%85OpenCV2.0



安裝VC++ 2008 Express



Visual C++ Express是微軟推出的一款免費集成開發環境,如果你沒有足夠資金購買Visual C++,你可以使用Visual C++ Express。本安裝說明撰寫時,最新的版本是Visual C++ 2008 Express.


Visual C++ 2008 Express可以從微軟網站下載安裝(http://www.microsoft.com/express/product/default.aspx )。


[編輯]


安裝OpenCV



從 http://www.opencv.org.cn/index.php/Download 下載OpenCV 2.0,並安裝,本文檔假定安裝目錄為:D:Program FilesOpenCV2.0


[編輯]


安裝CMake



從 http://www.cmake.org/cmake/resources/software.html 下載 Windows (Win32 Installer) 安裝。


[編輯]


編譯OpenCV



[編輯]


用CMake導出VC++項目文件



  • 運行cmake-gui,設置路徑為OpenCV安裝路徑(本文檔假定安裝位置為:D:Program FilesOpenCV2.0),並創建子目錄D:Program FilesOpenCV2.0vc2008,用於存放編譯結果。

  • 然後點 configure,在彈出的對話框內選擇 Visual Studio 9 2008。

  • 如果是VC++2008的Express版本,則不支持OpenMP,所以需要取消ENABLE_OPENMP選項,取消後再次選擇「Congfigure」,完成後選擇「Generate」。VC++ 2008(不是Express版本)支持OpenMP,如果你使用VC++2008,強烈建議不要取消這個選項。



註意:OpenCV2.1中沒有ENABLE_OPENMP選項,在安裝VC++2008時可以不管這個選項。








點擊看大圖


Enlarge

點擊看大圖






點擊看大圖


Enlarge

點擊看大圖






點擊看大圖


Enlarge

點擊看大圖





[編輯]


編譯 OpenCV Debug和Release版本庫



完成上一步驟後,將在D:Program FilesOpenCV2.0vc2008目錄下生成OpenCV.sln的VC Solution File,請用VC++ 2008 Express打開OpenCV.sln,然後執行如下操作:


  • 在Debug下,選擇Solution Explorer裡的 Solution OpenCV,點右鍵,運行"Rebuild Solution";如編譯無錯誤,再選擇INSTALL項目,運行"Build"。

  • 在Release下,選擇Solution Explorer裡的 Solution OpenCV,點右鍵,運行"Rebuild Solution";如編譯無錯誤,再選擇INSTALL項目,運行"Build"。



此時,OpenCV的*d.dll文件(for debug)和*.dll文件(for release)將出現在D:Program FilesOpenCV2.0vc2008bin目錄中;OpenCV的*d.lib文件(for debug)和*.lib文件(for release)將出現在D:Program FilesOpenCV2.0vc2008lib目錄;頭文件*.h出現在D:Program FilesOpenCV2.0vc2008includeopencv中。


可以被VC++ 2008 Express調用的OpenCV動態庫生成完畢。















點擊看大圖


Enlarge

點擊看大圖






點擊看大圖


Enlarge

點擊看大圖






點擊看大圖


Enlarge

點擊看大圖






點擊看大圖


Enlarge

點擊看大圖






點擊看大圖


Enlarge

點擊看大圖





[編輯]


配置Windows環境變數Path



將D:Program FilesOpenCV2.0vc2008bin加入Windows系統環境變數Path中。加入後可能需要註銷當前Windows用戶(或重啟)後重新登陸才生效。







點擊看大圖


Enlarge

點擊看大圖






點擊看大圖


Enlarge

點擊看大圖





[編輯]


為VC++ 2008 Express配置OpenCV環境



打開VC++ 2008 Express,菜單 Tools -> Options -> Projects and Solutions -> VC++ Directories


  • Show directories for選擇executable files,加入目錄 D:Program FilesOpenCV2.0vc2008bin

  • Show directories for選擇include files,加入目錄 D:Program FilesOpenCV2.0vc2008includeopencv

  • Show directories for選擇library files,加入目錄 D:Program FilesOpenCV2.0vc2008lib



關閉VC++ 2008 Express。







點擊看大圖


Enlarge

點擊看大圖






點擊看大圖


Enlarge

點擊看大圖





[編輯]


使用OpenCV 2.0編程



  • 打開VC++ 2008 Express,創建一個Win32控制台程式opencvhello;

  • 選擇Solution Explorer裡的opencvhello項目,點擊滑鼠右鍵,選擇Properties,在[鏈接器 LINKER]的[輸入INPUT]中:

  • 為項目的Debug配置增加 [依賴的庫 Additional Dependencies]:cxcore200d.lib cv200d.lib highgui200d.lib(註意,文件名cv200d.lib 可能是cv***d.lib等形式,具體應查看D:Program FilesOpenCV2.0vc2008lib。如果使用的是OpenCV2.1,應輸入:cxcore210d.lib cv210d.lib highgui210d.lib )

  • 為項目的Release配置增加[依賴的庫 Additional Dependencies]:cxcore200.lib cv200.lib highgui200.lib (註意:如果使用的是OpenCV2.1,應輸入:cxcore210.lib cv210.lib highgui210.lib)

  • 在 [配置屬性 Configuration Properties]- [General] -[字元集 Character Set] 修改為使用「多位元組字元集」 (由於2008預設是以Unicode字元集編譯的)

  • 編譯運行下麵的常式(需要將lena.jpg文件放在項目目錄下)。


/***********************************************************************
* OpenCV 2.0 測試常式
* 於仕琪 提供
***********************************************************************/

 
#include "stdafx.h"
#include "highgui.h"
 
//所有的以新風格命名的函數都在 cv 命名空間中
//如果希望不要每次都輸入 cv:: ,則可使用下麵語句
//using namespace cv;
 
int _tmain(int argc, _TCHAR* argv[])
{
 
const char* imagename = "lena.jpg";
 
cv::Mat img = cv::imread(imagename); // Matlab風格的 cvLoadImage 函數的另一種調用
if(img.empty())
{
fprintf(stderr, "Can not load image %sn", imagename);
return -1;
}
 
if( !img.data ) // 檢查是否正確載入圖像
return -1;
 
cv::namedWindow("image", CV_WINDOW_AUTOSIZE); //創建視窗
cv::imshow("image", img); //顯示圖像
 
cv::waitKey();
 
return 0;
}















點擊看大圖


Enlarge

點擊看大圖






點擊看大圖


Enlarge

點擊看大圖






點擊看大圖


Enlarge

點擊看大圖






點擊看大圖


Enlarge

點擊看大圖






點擊看大圖


Enlarge

點擊看大圖






點擊看大圖


Enlarge

點擊看大圖





[編輯]


作者



  • 於仕琪



註:使用OpenCV 2.1 的,請將上圖中的 *200.lib 和 *200d.lib 分別改為 *210.lib 和 *210d.lib



Win7 下使用opencv2.1 VC++2008時 該程式中載入圖像時要寫完整路徑,不然載入不了。 例如:

   const char* imagename = "lena.jpg";


需要修改為

   const char* imagename = "D:\lena.jpg";








0
意見






張貼留言















較新的文章


較舊的文章

首頁



Popular posts from this blog

倭马亚王朝

Gabbro

托萊多 (西班牙)