Ask Your Question

Hitching and Smoothness problem with videocapture::read

asked 2013-05-28 21:15:05 -0500

AlexGray gravatar image

So I'm having a problem with the VideoCapture::read function.

When I run this function:

void Camera::DoFrame( cv::Mat& im, vector<Location> &locations)

    TheVideoCapturer >> im;

    locations = processFrame(im);
    //imshow("video", im);

The average time taken is 33 milliseconds, Most of that time is taken up by the TheVideoCapturer >> im; This is fine as that is a good frame rate, however it has periods where the time will spike up to 250ms. This obviously produces problems with the smoothness of my video, one which I wanted to fix. I think it also might be related to the video skipping occcasionly.

After suspecting my camera and another of other issues, I found that by uncommenting 2 lines in the above sample of code, I could get the video to out put much more consistantly, with the longest time the read function takes is 30ms, though the average is 2ms. This is more like what i would expect as a frame rate. It also seems to relieve my problem of the video being not smooth enough. The only problem with this is that I neither want to output a video from my camera, or wait 30ms if I can help it. Is there something I misunderstand about the read method? Has anyone expereienced something similar?

I am using opencv version 2.4.5, I experience the same bug in both visual studio and mingw, and get the same problem on both a logitech pro 9000 and a logitech pro c910


edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted

answered 2013-05-29 11:53:13 -0500

berak gravatar image

cv::waitKey() is actually doing much more, than waiting for keys.

in fact, since you're on win, the whole win32 message-pump is happening in there ( messages to update/draw the window, keypress/mouse events, etc. )

so, if the process-scheduler decides to chop off a few cycles from your prog, messages will get delayed, resulting in notable hickups in the video playback.

edit flag offensive delete link more


I ended up implementing my own handler of the message pump, because I needed to do some specific stuff but this was exactly what I need to know thanks.

AlexGray gravatar imageAlexGray ( 2013-06-11 18:07:52 -0500 )edit
Login/Signup to Answer

Question Tools


Asked: 2013-05-28 21:15:05 -0500

Seen: 111 times

Last updated: May 29 '13