How do I capture images in OpenCV and saving in pgm format?

前端 未结 5 1339
一生所求
一生所求 2020-12-20 04:28

I am brand new to programming in general, and am working on a project for which I need to capture images from my webcam (possibly using OpenCV), and save the images as pgm f

5条回答
  •  情歌与酒
    2020-12-20 04:55

    I believe that the format is chosen from the extension of the filename - so assuming your opencv lib's are linked against the appropriate libs you can do something like: (this is from memory, might not be correct.)

    CvCapture* capture = cvCaptureFromCam(0);
    IplImage* frame = cvQueryFrame(capture);
    while (1) {
        frame = cvQueryFrame(capture);
        cvSaveImage("foo.pgm", &frame);
        sleep(2);
    }
    cvReleaseImage(&frame);
    cvReleaseCapture(&capture);
    

提交回复
热议问题