views:

30

answers:

2

Hi folks,

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 files.

What's the simplest way to do this? Willow Garage provides this code for image capturing:

http://opencv.willowgarage.com/wiki/CameraCapture

Using this code as a base, how might I modify it to:

  1. capture an image from the live cam every 2 seconds
  2. save the images to a folder in pgm format

Thanks so much for any help you can provide!

A: 

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);
jskaggz
A: 

If you don't need superaccurate 2seconds then simply put a sleep(2) or Sleep(2000) in the while(1) loop to wait fro 2seconds before each grab,

Write images with cvSaveImage() just put the extention .pgm on the filename and it will use pgm.

Martin Beckett