Ask Your Question

Revision history [back]

I had the same issue. Any VideoCapture property that could have been useful returned -1.0 in my case, so I had to figure it out myself. I made a simple program that reads and displays a frame from camera on a key press:

VideoCapture camera(0);
Mat frame;
while(true) {
    camera.read(frame);
    imshow("window", frame);
    waitKey();
}

I put something in front of the camera and counted how many frames it took until it appeared on the screen, then took it away and did the same. Turns out in my case there are exactly 5 frames buffered. And as new frames are available, the last one is being overwritten. So if my slow running operation takes more than 5 frames, I can easily use the following:

...
for(int i = 0; i < 5; i++) {
    camera.grab();
}
camera.retrieve(frame);
process(frame);
...

In the worst case, if your operation is instant, you will have to wait for 4 extra frames, so it will reduce your fps to 20%. But either way, the displayed image, once you get it, will be "current".