cv :: imshow有时是很慢 [英] cv::imshow sometimes is very slow

查看:1410
本文介绍了cv :: imshow有时是很慢的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个问题与 cv :: imshow 。它通常消耗大约1-2毫秒的处理时间为我的图像大小,但在我的处理流水线的某一点,它使用4-8毫秒相同类型的图像。

I've got a problem with cv::imshow. It normally consumes about 1-2 ms processing time for my image size but at some point in my processing-pipeline it uses 4-8 ms for the same kind of images.

我有一个方法

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

image 成员变量和highgui窗口创建在其他地方。
时间测量与 boost :: posix_time ptime time_duration 配合使用。

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

cvStartWindowThread();

已被调用。

,如果 displayImage()在复杂处理链(从视频文件加载图像,一些预处理等)中调用, cv :: imshow 变得非常慢,而在暂停视频中调用以重绘更新的图像非常快。

The point is, that if displayImage() is called within a complex processing chain (loading image from videofile, some preprocessing etc), cv::imshow becomes very slow, while a call in a "paused" video to redraw an updated image is very fast.

如果添加 cv :: waitKey(10)在时间测量的开始之前, cv :: imshow 也变得快。所以可能有一些(gui?)事情,必须处理阻止 cv :: imshow cv :: waitKey(40)在等待键盘输入以控制(例如暂停/恢复)视频的单独线程中被调用。
据我所知, cv :: imshow 是在某种类型的队列中执行的,在 cv :: waitKey times?!?在哪里可以找到有关在那段时间执行的所有任务的信息?也许我可以重新安排我的代码的一些部分(现在真的很复杂),允许所有时间更快的 imshow

If I add a cv::waitKey(10) before the time measurement's beginning, cv::imshow becomes fast, too. So there might be some (gui?) things which have to be processed which block cv::imshow? cv::waitKey(40) is called in a separate thread in loop which waits for keyboard input to control (e.g. pause/resume) the video. As far as I know, cv::imshow is performed in some kind of queue which is processed during cv::waitKey times?!? Where can I find information about all the tasks which are performed during that times? Maybe I can rearrange some parts of my code (really complex by now) to allow faster imshow all the time.

因此,在 cv :: imshow 调用中会发生什么,以及在不同情况下同一个调用的慢/快执行的原因是什么?

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

EDIT :我在常规执行和处理暂停模式之间认识到的一个区别是,在暂停模式下,该方法从绑定的鼠标回调函数从 windowThread ?)

EDIT: one difference I recognized between regular execution and processing in 'pause' mode is, that in pause mode the method is started from a bound mouse callback function (that's from within the windowThread?) while in regular mode it's started from the main processing thread.

推荐答案

这是OpenGL的典型问题,OpenCV窗口可以使用OpenGL创建。 SwapBuffers 有一个问题(请参阅 SDL_GL_SwapBuffers()是间歇性慢的和其他),通常通过在它之前添加一个小睡眠来解决。

This is a typical problem with OpenGL, and the OpenCV windows can be created using OpenGL. There is a problem with SwapBuffers (see SDL_GL_SwapBuffers() is intermittently slow and others), which is often solved by adding a small sleep before it.


  • 视频驱动程序中的垂直同步可能会有帮助。

  • 没有打开太多的图片窗口(许多OpenCV程序的典型瘟疫)。

  • 与OpenGL不同的API来创建窗口可能有帮助(可能需要重新编译 highgui )。

  • Disabling vertical synchronization in the video drivers may help.
  • Not having too many image windows opened (a typical plague of many OpenCV programs) helps.
  • Using a different API than OpenGL to create the windows may help (will likely require recompiling highgui).

这篇关于cv :: imshow有时是很慢的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆