Ask Your Question

Revision history [back]

cvcapture / image flush / lag

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

click to hide/show revision 2
No.2 Revision

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

berak gravatar image

cvcapture / image flush / lag

I'm using something like: like:

VideoCapture webcam;

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