Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Iterating Through a Video Frame by Frame

Hi Folks, In the code below (for playing a video), how does the capture object "know" how to iterate through the video frame by frame? Usually in a while or for loop we use some sort of incrementing technique such as i++ etc.

I think I have seen this before with stream extraction iterators where they automatically increment to read the contents of a buffer but I am not sure how it works. I tried to view the contents of the Videocapture class but can only find the definition (which includes an overloaded>> function) but can not see how it is implemented.

Thanks,

int main()

{ namedWindow("Video"); VideoCapture cap;

cap.open("video.avi");

Mat frame;

while(1)
{
    cap>>frame;     
    if(!frame.data) 
        break;

    imshow("Video", frame);

    if(waitKey(300) >= 0)   
        break;              
}

}