Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Grabbing the image skips current (or next) frame.

Hey there, I've recently realised that all of my output videos are twice as fast as the original, so i made the program print out the current frame and noticed that it was increasing by 2 each time (2,4,6,8...). When I removed the "cap>>currentImage;" it printed 1,2,3,4,...

I just don't understand why this is happening. Is there a mistake in the way I'm printing the frame? Any help would be appreciated.

int main (int argc, char *argv[]) {

    /// CHANGE INPUT FILE HERE
    Mat currentImage;
    VideoCapture cap("testcut.avi");//"herman.avi"

    if (!cap.isOpened()) {
            cout << "Failed to open the input video" << endl;
            exit(5);}

    for(;;){
        cap>>currentImage;
        if (!cap.grab())
        {
            cout << "\n End of video, looping" << endl;
            cap.set(CV_CAP_PROP_POS_AVI_RATIO, 0);
        }
    waitKey(80);
    cout<<"frame number=         "<<cap.get(CV_CAP_PROP_POS_FRAMES)<<endl;

    }
    return 0;
}