I'm agree with @StevenPuttemans. The correct and efficient way depends on GUI you are using: Win32,MFC, QT, wxWidgets, GTK, OpenGL, ... and/or CUDA, OpenCL and so on.
OpenCV provides a memory bank that you have to copy to (or share with) the graphic device and this is done by some user interface library. HighGUI is simplest one.
imshow
and waitKey(delay)
uses basic functions from platform you are using.On Windows, the Win32 library is used by default.
imshow
copy the cv::Mat into a DIB image and Invalidate the Rect related to window on the screen.
Despite of its name, the waitKey
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.
This means that waitKey
takes care of (executes) all GUI events such as show, refresh a window and so on. In addictions it waits for N millisecs a key press over an OpenCV window. I think it should be considered as UpdateGUI+WaitKey
Sure you will waste N millisecs waiting an usefulness key press but you have to wait also to serve all GUI events.
If you want to use HighGUI from OpenCV, you could write your own UpdateGUI hacking the waitKey code around delay<=0
and choose to serve only message for a specific window (window->hwnd == message.hwnd
). Not so easy and maybe not so useful but I think feasible.
(in exactly that order)
Actually, this is something I've wondered about too. Is this the recommended way of displaying things as fast as possible? I know if I've got several imshow windows open the ones not with focus sometimes stutter and don't show every frame.
Assuming every other part of the program has been profiled and optimized, then what? Is this better than calling updateWindow? Actually, I can test that myself.
Ok, updateWindow only applies to OpenGL windows, so not what I thought it was.
As far as I can tell, waitKey(1) is the fastest way to refresh windows.
It is the fastest way, simply because
imshow
windows should not be used for your final application :D OpenCV is a backend library, not a user interface library. Those windows are there for the sole purpose of debugging!@StevenPuttemans: What would be the "correct" way to rapidly throw images on the screen in the final application (managed Visual C++)?
My application works and was profiled and
imshow/waitkey(1)
is a bottleneck...@Guyygarty, actually that is one though one to answer since I only make proof of concept software and thus when passing the code to the UI step, I am basically not involved anymore in my job. I am thus not sure how I could provide you with the best answer.
in mfc,use ontimer