1 | initial version |
I know that it is required if you want to show changes in an image during a loop, or even the loop itself. When you call imshow
it doesn't immediately draw itself (in my experience and afaik), it requires a call to waitKey
before it attempts to process it's event loops. This is because waitKey
is simply waiting for a delay, and during this delay Highgui runs whatever tasks need to be done drawing.
HighGui cannot process windows events like redraw, resizing, input event unless you call waitKey(delay)
, I found this info out from firsthand experience and from this post http://stackoverflow.com/a/12452139/1808164
As far as when it is recommended, I'd say anytime you need to update display changes to a user you should call it, or if you're waiting for a user to give you some input. Hope this helps.
2 | updated with documentation |
I know that it is required if you want to show changes in an image during a loop, or even the loop itself. When you call imshow
it doesn't immediately draw itself (in my experience and afaik), it requires a call to waitKey
before it attempts to process it's event loops. This is because waitKey
is simply waiting for a delay, and during this delay Highgui runs whatever tasks need to be done drawing.
HighGui cannot process windows events like redraw, resizing, input event unless you call waitKey(delay)
, I found this info out from firsthand experience and from this post http://stackoverflow.com/a/12452139/1808164
As far as when it is recommended, I'd say anytime you need to update display changes to a user you should call it, or if you're waiting for a user to give you some input. Hope this helps.
The documentation here: http://docs.opencv.org/modules/highgui/doc/user_interface.html#imshow should tell you pretty much everything you want to know about why this all is, but to qoute:
This function is the only method in HighGUI that can fetch and handle events, so it needs to be called periodically for normal event processing unless HighGUI is used within an environment that takes care of event processing.