Cv :: imshow sometimes very slow

I have a problem with cv::imshow . It usually consumes about 1-2 ms of processing time for my image size, but at some point in my processing, it uses 4-8 ms for images of the same type.

I have a method

 void Tool::displayImage() { startTimeMeasure(); cv::imshow("output",image); evaluateTimeMeasure(); } 

image is a member variable, and a highgui window is created somewhere else. Time measurement works with boost::posix_time ptime and time_duration .

 cvStartWindowThread(); 

.

The fact is that if displayImage() is called in a complex processing chain (loading an image from a video file, some preliminary processing, etc.), cv::imshow becomes very slow, and a call in a “paused” video to redraw the updated image is very fast.

If I add cv::waitKey(10) before starting the time measurement, cv::imshow also fast. So there may be some (gui?) Things that need to be handled that block cv::imshow ? cv::waitKey(40) is called in a separate thread in a loop, which waits for keyboard input to control (for example, pause / resume) video. As far as I know, cv::imshow is executed in some kind of queue that is processed during cv::waitKey times?!? Where can I find information about all the tasks that are performed at this time? Maybe I can change some parts of my code (really complicated by now) to speed up imshow all the time.

So, what happens in the cv::imshow and what could be the reasons for the slow / fast execution of the same call in different situations?

EDIT : One difference that I recognized between regular execution and processing in pause mode is that in pause mode, the method is started from the linked line callback function (which is from windowThread ?), While in normal mode it starts from the main processing thread.

+7
c ++ performance opencv imshow highgui
source share
1 answer

This is a typical OpenGL issue, and OpenCV windows can be created using OpenGL. There is a problem with SwapBuffers (see SDL_GL_SwapBuffers () intermittently slowly and others), which is often solved by adding a little sleep in front of it.

  • Disabling vertical sync in video drivers may help.
  • Not too many image windows (a typical plague of many OpenCV programs).
  • Using a different API than OpenGL to create windows can help (most likely, you will need to recompile highgui ).
+3
source share

All Articles