opencv 获取摄像头图像
#include "stdafx.h" #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; }
这个感觉写的挺好的