Opencv imshow()在更新时冻结 [英] Opencv imshow() freezes when updating

查看:244
本文介绍了Opencv imshow()在更新时冻结的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于我的图像处理算法,我使用的是python/OpenCV.我的算法的输出应在同一窗口中一遍又一遍地更新.

For my image processing algorithm I'm using python / OpenCV. The output of my algorithm shall be updated im the same window over and over again.

但是有时窗口会冻结并且根本不更新,但是与此同时,算法仍在运行并多次更新图片.在此Ubuntu计算机上,该窗口变为深灰色.

However sometimes the window freezes and doesn't update at all, but the algorithm is still running and updated the picture a multiple times in the meantime. The window turns dark gray on this Ubuntu machine.

以下是相关代码的摘录:

Here is an excerpt of the involved code:

for i in range(0,1000):
    img = loadNextImg()
    procImg = processImg(img)
    cv2.imshow("The result", procImg)
    cv2.waitKey(1)

N.B.:processImg()大约需要1-2秒的过程.第cv2.imshow(procImg)行在第一个实例中创建窗口(即没有先前的调用)

N.B.: processImg() takes about 1-2 s for its procedures. The line cv2.imshow(procImg) creates the window in first instance (i.e. there is no preceding invocation)

推荐答案

我的建议是使用Matplotlib pyplot显示图像.我是通过以下方式完成的.

My suggestion is to use Matplotlib pyplot for displaying the image. I do it the following way.

import matplotlib.pyplot as plt
# load image using cv2....and do processing.
plt.imshow(cv2.cvtColor(image, cv2.BGR2RGB))
# as opencv loads in BGR format by default, we want to show it in RGB.
plt.show()

我知道它不能解决cv2.imshow的问题,但是可以解决我们的问题.

I know it does not solve the problem of cv2.imshow, but it solves our problem.

这篇关于Opencv imshow()在更新时冻结的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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