Ask Your Question
0

delay in frame processing through opencv iOS

asked 2015-02-16 01:03:19 -0600

lakshmi gravatar image

Hi,

I am using OpenCV's VideoCapture , but the problem I am facing is that the image that I take at a certain moment does not show the latest thing that the camera sees. That is, if I take an image at timestamp t, it shows what the camera saw at timestamp (t - delta), so to say. How can I resolve this delay issue in processing frames. I have searched in google and many of them mentioned like may be due to _videoCapture->grab() function. If it so, please suggest me the alternative for _videoCapture->grab()) function to reduce this delay time? Help is highly appreciable.

Thanks in advance.

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
1

answered 2015-02-16 02:02:55 -0600

This is not due to OpenCV but due to your camera configuration. Please open up the camera in the supplied camera configuration software by the manufacturer and make sure that the image buffer is set to 1 frame. Basically OpenCV pulls the memory buffer for a new frame each time you request one, if that buffer still contains old images, then your screwed. A small workaround could be to discard around 10 pulls by applying this code, and adapting the amount until you get the current frame each time.

VideoCapture capture(1);
Mat image;
// Loop for emptying buffer
for(int i = 0; i < 10; i++){
   capture >> image;
}
capture >> image;
imshow("fresh frame", image.clone());

However adapting the buffer is way better.

edit flag offensive delete link more

Comments

Hi , Thanks a lot for your solution.I have added the code like as you mentioned above.Please just verify whether it is correct or not.

 if (_videoCapture && _videoCapture->grab())
    {
        for(int i=0;i<10;i++)
        {
        (*_videoCapture) >> _lastFrame;
        }
         (*_videoCapture) >> _lastFrame;
        imshow("fresh frame",_lastFrame.clone());
        [self processFrame];
}

I have tried this. But still I am getting the same delay. Correct me if there is any wrong in the code.

Thanks in advance.

lakshmi gravatar imagelakshmi ( 2015-02-17 06:09:10 -0600 )edit

First of all, did you look up how large your memory buffer is? If it can contain 256 images, than the delay is still normal. And please, why use pointers on VideoCaptures? They already define smart pointers internally, so you make it more complex than needed!

StevenPuttemans gravatar imageStevenPuttemans ( 2015-02-17 06:17:22 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2015-02-16 01:03:19 -0600

Seen: 392 times

Last updated: Feb 16 '15