opencv 获取摄像头图像

http://www.cnblogs.com/epirus/archive/2012/06/04/2535190.html

#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;
}
原文地址:https://www.cnblogs.com/zkwarrior/p/4869953.html