cvcapture / image flush / lag

asked 2015-10-12 13:11:57 -0600

SASA gravatar image

updated 2015-10-12 13:22:05 -0600

berak gravatar image

I'm using something like:

VideoCapture webcam;

while(true){
webcam>>img;
imshow(name,img);
// do something slow here to work out the feedback which changes the image
// set feedback
// repeat
}

The problem is that my retrieved image does not seem to be the latest image and I keep reading several "old" images before I get the current one - it looks like there is a queue or pipeline of images in the system and I have to consume the old ones before I get to the current one, since there is something slow and asynchronous in the loop and I keep getting old frames my feedback is out of sync and wrong.

I'd like to do something akin to flushing all the old images out to ensure that when I read the camera it is the most recent data available.

I've tried simply inserting delays at various stages but these don't help and I have a lag of a few frames. Inserting webcam.grab(); several times before I read the data seems to help but is not entirely reliable and slows things down a lot.

Any suggestions as to how to flush through the old data and ensure the image I get comes from the time after the feedback I set takes effect?

The only way I can ensure this at the moment is to release() and reopen but this is very very slow.

Using linux with a v4l (v4l2) webcam.

Thanks SA

edit retag flag offensive close merge delete

Comments

could you try the code here and tell me the given FPS value of your camera

sturkmen gravatar imagesturkmen ( 2015-10-12 13:35:32 -0600 )edit

there is a very new update on v4l2 webcam. try to update.

sturkmen gravatar imagesturkmen ( 2015-10-12 13:50:31 -0600 )edit