0

Within C++ (also using OpenCV) I'm creating a loop which displays a new image from file each iteration. To achieve this I've had to add in waitKey(1) otherwise only a blank window is displayed. I was just wondering why this millisecond delay must be included for the image to show each iteration and, if possible, if there is a method to display the image without requiring this delay.

Thanks in advance!

MSTTm
  • 293
  • 3
  • 7
  • 18
  • if performance relevant, care that waitKey(1) doesnt mean it will wait 1ms, but AT LEAST 1ms... On windows it will typically wait a minimum of 5-15ms afair. If necessary you should code your own displaying with OpenGl, Qt or something. OpenCV GUI is more about a fast coded gui for debugging and simple visualization, typically not for commercial code. – Micka Jul 24 '15 at 08:13
  • Ideally I'd prefer to remove this delay entirely, so I will have to look into this method using OpenGL or the like. Thanks for the heads up on that one! – MSTTm Jul 26 '15 at 23:18

1 Answers1

1

The function waitKey() waits for key event for a "delay" (here, 30 milliseconds). As explained in the OpenCV documentation, HighGui (imshow() is a function of HighGui) need a call of waitKey reguraly, in order to process its event loop.

Ie, if you don't call waitKey, HighGui cannot process windows events like redraw, resizing, input event etc. So just call it, even with a 1ms delay :)

what does waitKey (30) mean in OpenCV?

Community
  • 1
  • 1
Chol Nhial
  • 1,327
  • 1
  • 10
  • 25