Camera buffer

With openframeworks I created a robotproject in which a vision feedback is applied. During the initialisation procedure a few frames are grabbed. However, I notice that the frames are ‘old’, (over 2 seconds old). It seems that there is a buffer that gives me old frames which screw up my procedure. Is there a way to empty the buffer or to set it to 0 (or 1 ) frames?

OF 0.062 with codeblocks 8.02 on windows XP, using a logitech c250 webcam.

if you have 2 seconds of latency, something is seriously wrong. there is generally anywhere from 2 to 4 frames of latency. as your framerate increases, your latency will decrease. if you can reduce the resolution of the camera and use ofVideoGrabber::setDesiredFramerate() to try a higher fps like 30 or maybe 60, that should help.

there is no procedure in OF for emptying the video buffer – i’m pretty sure that’s handled by the grabber implementation (quicktime, direct show, etc). if you want to make sure you are getting the latest frame, you can try calling update()/isFrameNew() repeatedly until isFrameNew() returns false. this might help if your app is running at a very low framerate.

I now realise that my problem description is a bit weak.

In the setup function I initialise my robots. I grab a frame, proces it to know the positions of my robots. That I command one robot to move and then grab a frame and proces it know see which one moved. For the movement of the robot the script is halted for two seconds. The frame grabbed immidiately after the script is halted is old. When I continously grab frame (in the draw function) there is no problem.

ok, that’s a bit like i said then – there is normally 2-4 frames of latency due to an internal buffer as you suspected. it’s not OF’s buffer, but the per-OS video grabber library.

if you want to make sure you have the most recent frame, you could try grabbing 4 frames instead of just one.

int frames = 0;  
while(frames < 4) {  
  if(camera.isFrameNew()) {  

when that code is done executing you should have the most recent frame.