Ask Your Question

WaitKey without waiting?

asked 2014-03-26 19:08:12 -0600

Dave92F1 gravatar image

Is there a way to call WaitKey without incurring a (minimum) 1 millisecond block?

Suppose I have a 300 frames/sec camera & display - to display each frame I need to call waitkey(1) 300 times each second (because you have to call waitkey to get imshow to work), which consumes 30% of my entire CPU.

Most of that time is just sitting there waiting for the keyboard, at 1 ms per call.

This seems like a huge waste of CPU time.

Is there some way to call WaitKey without the needless wait-for-keyboard delay?

WaitKey(0.0000000001) I suppose would do it, but WaitKey only takes integers...

edit retag flag offensive close merge delete


Do you necessarily need to display all frames?

Moster gravatar imageMoster ( 2014-03-27 02:28:45 -0600 )edit

imho, you're making up a problem where none exists.

no, you don't have to care about 300 fps. an average webcam won't be faster than 30 fps, an expensive one maybe 100.

the time spent there is used to blit/update the image ( no, that does not happen in imshow ), and that will be already more than a millisecond

you don't even have to use the highgui api for showing your images, just build something with qt/winforms, whatever

berak gravatar imageberak ( 2014-03-27 11:17:11 -0600 )edit

1 answer

Sort by ยป oldest newest most voted

answered 2014-03-27 14:37:02 -0600

xaffeine gravatar image

OpenCV does not have a priority on high-efficiency GUI implementation. If you don't like calling waitkey(1), you may need to use another toolbox for image display. Some OpenCV users use QT for that, others use lower-level API.

edit flag offensive delete link more

Question Tools


Asked: 2014-03-26 19:08:12 -0600

Seen: 10,145 times

Last updated: Mar 27 '14