I've been trying to find/implement a seek and rewind function (for video (.avi)) using OpenCV in C++, but I cant find a way of doing it, other than going through the entire file once and saving each image. Is there any other way?
Any help would be much appreciated; Thanks ahead of time!
Using cvSetCaptureProperty() you can cycle through frames, either in miliseconds or by ordinal frame number.
int cvSetCaptureProperty( CvCapture* capture, int property_id, double value );
property_id is a property you would need to use. It can be one of the following:
The first two is of your interest.
EDIT: more info :)
You can cycle through frames just by repeatedly calling the mentioned function with various frame indices.
cvSetCaptureProperty(capture, CV_CAP_PROP_POS_FRAMES, frameIndex);
Example:
IplImage* frame;
CvCapture* capture = cvCreateFileCapture("test.avi");
/* iterate through first 10 frames */
for (int i = 0; i < 10; i++)
{
/* set pointer to frame index i */
cvSetCaptureProperty(capture, CV_CAP_POS_FRAMES, i);
/* capture the frame and do sth with it */
frame = cvQueryFrame(capture);
}
You could put similar code to execute each time user clicks a button to forward/rewind the video.
The C++ method (OpenCV 2 and higher) would be to use this method instead with the same property_id and value.
bool VideoCapture::set(int property_id, double value)