Thursday, December 27, 2007

OpenCV: capture the frame

To open the video from camera or from the avi file, you may use the following two functions:

CvCapture *cap = cvCaptureFromCAM(0);
CvCapture *cap = cvCaptureFromAVI("test.avi");

Use the following functions to capture one frame:

IplImage *img = 0;
if (!cvGrabFrame(cap))
{
printf("cannot grab\n");
exit(0);
}
img = cvRetrieveFrame(cap);

Remember: do NOT use cvReleaseImage to release img.
You may also use the followings to capture one frame:

IplImage *img = 0;
img = cvQueryFrame(cap);
if (!img)
{
printf("cannot grab\n");
exit(0);
}
Use 'cvReleaseCapture(&cap);' in the end.

No comments:

Post a Comment