SETP1:下載 OpenCV-2.3.0-win-superpack.exe,解壓縮檔案到 C:\OpenCV2.3
SETP2:設定 PATH 環境變數
C:\OpenCV2.3\build\bin;C:\OpenCV2.3\build\x86\vc10\bin;
image
SETP3:在 Visual Studio 2010 中建立 VC++ Win32 主控台應用程式
2011-07-24_142558
SETP4:點選 專案->屬性->VC++ 目錄 設定
Include 目錄:
C:\OpenCV2.3\build\include\opencv;C:\OpenCV2.3\build\include\;
程式庫目錄:
C:\OpenCV2.3\build\x86\vc10\lib;

image
SETP5:點選 專案->屬性->連結器->輸入 設定
其他相依性:
opencv_core230d.lib;opencv_highgui230d.lib;opencv_imgproc230d.lib;opencv_legacy230d.lib;opencv_ml230d.lib;opencv_video230d.lib;
image

程式碼:
#include "stdafx.h"
#include 
#include 
 
int _tmain(int argc, _TCHAR* argv[])
{    
    int c;
    CTime time;
    IplImage *img;    
    CvCapture* capture = cvCaptureFromCAM(1);    
    cvNamedWindow("mainWin", CV_WINDOW_AUTOSIZE);    
    cvMoveWindow("mainWin", 5, 5);    
 
    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;
}

參考網站: