Just My Life & My Work

之前用Dev C++ 4.9.9.2安裝過OpenCV,但現在想用Visual Studio 2010安裝,畢竟VS一直在進化,而且功能相當齊全,想必未來會陸續用到,因此特地轉換平台。

很感謝已經有前人在網路上分享安裝經驗,所以我直接按照他的步驟來進行安裝。我的作業系統是Windows XP 32bit

Step1:下載OpenCV-2.3.0-win-superpack.exe
Step2:解壓縮檔案到 C:\OpenCV2.3(方便設定路徑)
Step3:設定 PATH 環境變數我的電腦->內容->進階->環境變數

C:\OpenCV2.3\build\bin;C:\OpenCV2.3\build\x86\vc10\bin;

Step4:在 Visual Studio 2010 中建立 VC++ Win32 主控台應用程式
Step5:點選 專案->屬性->VC++目錄 設定
  • Include目錄

C:\OpenCV2.3\build\include\opencv;C:\OpenCV2.3\build\include;

  • 程式庫目錄

C:\OpenCV2.3\build\x86\vc10\lib;

Step6:點選 專案->屬性->連結器->輸入 設定
  • 其他相依性

opencv_core230d.lib;opencv_highgui230d.lib;opencv_imgproc230d.lib;
opencv_legacy230d.lib;opencv_ml230d.lib;opencv_video230d.lib;

未來可依需求到C:\OpenCV2.3\build\x86\vc10\lib;查看其它.lib檔並加入其中。

想要知道是否安裝成功,可以使用以下程式碼測試:

/**
	Theme: Camera Display
	Compiler: Dev C++ 4.9.9.2
	Date: 101/01/03
	Author: HappyMan
	Blog: https://cg2010studio.wordpress.com/
*/
#include <highgui.h>

int main()
{
	int c;
	// allocate memory for an image
	IplImage *img;
	// capture from video device #1
	CvCapture* capture = cvCaptureFromCAM(1);
	if(!capture) { printf("\nCouldn't open the camera\n");}
	// create a window to display the images
	cvNamedWindow("mainWin", CV_WINDOW_AUTOSIZE);
	// position the window
	cvMoveWindow("mainWin", 500, 500);
	while(1)
	{
		// retrieve the captured frame
		img=cvQueryFrame(capture);
		// show the image in the window
		cvShowImage("mainWin", img );
		// wait 10 ms for a key to be pressed
		c=cvWaitKey(10);
		// escape key terminates program
		if(c == 27)
		break;
	}
 return 0;
}

CvCapture* capture = cvCaptureFromCAM(1);

如果不知道自己的webcam編號,可以試試看-1、0、1、2

也可以使用以下程式碼測試:

/**
	Theme: Camera Display
	Compiler: Dev C++ 4.9.9.2
	Date: 101/01/03
	Author: HappyMan
	Blog: https://cg2010studio.wordpress.com/
*/
#include <atltime.h>
#include <highgui.h>

int main()
{
    int c;
    CTime time;
    IplImage *img;
    CvCapture* capture = cvCaptureFromCAM(1);
    cvNamedWindow("mainWin", CV_WINDOW_AUTOSIZE);
    cvMoveWindow("mainWin", 50, 50);

    while(1)
    {
        img=cvQueryFrame(capture);
        cvShowImage("mainWin", img );
        c=cvWaitKey(10);

        //按 s 鍵儲存成 jpg 檔
        if(c=='s'){
            time = CTime::GetCurrentTime();
            CStringA filename(time.Format(CString("%Y%m%d%H%M%S"))+".jpg");
            cvSaveImage(filename,img);
        }

        //按 ESC 鍵離開
        if(c == 27)
        break;
    }

    cvReleaseImage(&img);
    cvDestroyWindow("mainWin");

    return 0;
}

此程式可以按s鍵來儲存所看到螢幕的影像為檔案。

以上是用32bit作業系統在Windows XP安裝(Visual Studio 2010和Visual C++ 2010 Express皆可),我試過64bit作業系統在Windows 7安裝,然而只能在Visual C++ 2010 Express成功安裝,如果有人成功在Visual Studio 2010安裝,請跟我說,謝謝!

若是64bit的話,x86改成x64,可以剪貼路徑測試是否正確。

參考:Visual Studio 2010 安裝 OpenCV 2.3 ( WebCam)Getting Started with OpenCV 2.3 in Microsoft Visual Studio 2010 in Windows 7 64-bit

Comments on: "[OpenCV] Visual Studio 2010 安裝 OpenCV 2.3" (8)

  1. Nick 的大頭貼

    我問題解決了但是在wi7下設定終究還是怪怪,所以我換XP跑就可以,但是我測試第2隻程式反而找不到atltime.h,不知是不是要去哪設定?

    • HappyMan 的大頭貼

      糟糕~我忘了程式檔放哪了,不過atltime.h跟OpenCV沒有直接關係,就請忽略第二支程式吧!第一支程式能成功執行,就代表你安裝成功了!

  2. Nick 的大頭貼

    請問我在win7 32bit下,按照上面設定為什麼會跑出遺失opencv_highgui230d.dll ??是我哪理設定問題嗎?

    • HappyMan 的大頭貼

      在C:\OpenCV2.3\build\x86\vc10\lib目錄底下找的到opencv_highgui230d.dll這個檔嗎?如果有的話,問題就解決囉!對了,我這路徑是Win XP 32bit喔~跟你的Win 7 32bit應該相去不遠才是:)

  3. 未知 的大頭貼

    […] 之前寫過Visual Studio 2010 安裝 OpenCV 2.3,不久又看到OpenCV 2.4 beta釋出,剛好裡頭有個技術我需要用到,於是又下載來安裝使用。 […]

  4. 未知 的大頭貼

    […] Visual Studio 2010 安裝 OpenCV 2.3 2012 年 04 月 10 日 Reblogged from 逍遙文工作室: 之前用Dev C++ 4.9.9.2安裝過OpenCV,但現在想用Visual Studio […]

  5. 未知 的大頭貼

    […] 安裝可參考:Visual Studio 2010 安裝 OpenCV 2.3或Dev-C++4.9.9.2 安裝 OpenCV 2.0。 […]

  6. HappyMan 的大頭貼

    Reblogged this on 逍遙文工作室 and commented:

    這個是reblog測試喔!

回覆給[OpenCV] Visual Studio 2010 安裝 OpenCV 2.4 beta « 逍遙文工作室 取消回覆

這個網站採用 Akismet 服務減少垃圾留言。進一步了解 Akismet 如何處理網站訪客的留言資料

標籤雲