http://iammic.pixnet.net/blog/post/34304039-visual-studio-2010%EF%BC%9Aopencv-2.3-%E4%BD%BF%E7%94%A8-webcamVisual Studio 2010:OpenCV 2.3 使用 WebCam
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;
SETP3:在 Visual Studio 2010 中建立 VC++ Win32 主控台應用程式
SETP4:點選 專案->屬性->VC++ 目錄 設定
Include 目錄:
C:\OpenCV2.3\build\include\opencv;C:\OpenCV2.3\build\include\;
程式庫目錄:
C:\OpenCV2.3\build\x86\vc10\lib;
SETP5:點選 專案->屬性->連結器->輸入 設定
其他相依性:
opencv_core230d.lib;opencv_highgui230d.lib;opencv_imgproc230d.lib;opencv_legacy230d.lib;opencv_ml230d.lib;opencv_video230d.lib;
程式碼:
#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;
}
參考網站:
0 意見
張貼留言