通过 cv2.imshow() 显示的图像窗口弹出窗口对我来说关闭得非常快

发布于 2025-01-12 10:50:48 字数 249 浏览 4 评论 0原文

只是一个示例代码

import cv2 as cv

img = cv.imread('book.jpg')
cv.imshow('img', img)

cv.waitKey(0)

窗口打开后关闭,我什至无法正确看到图像。

我认为发生这种情况是因为我使用的是 WSL (Linux),但在 Windows 中我也发生了同样的事情。

同样的事情在我朋友的电脑上运行得很好。这里可能有什么问题?

Just a sample code

import cv2 as cv

img = cv.imread('book.jpg')
cv.imshow('img', img)

cv.waitKey(0)

As soon as the window opens, it closes, I am not able to even see the images properly.

I thought it was happening because I was using WSL (Linux) but the same thing is happening for me in windows too.

The same thing works fine on my friends computer. What could be the issue here?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

[浮城] 2025-01-19 10:50:48

因此,解决此问题的方法是将 destroyAllWindows 任务添加到队列中并延迟它。

新代码将

import cv2 as cv

img = cv.imread('book.jpg')
cv.imshow('img', img)

cv.waitKey(0)
cv.destroyAllWindows()
cv.waitKey(1)

感谢 @AbhinavMathur 评论

So a workaround for this is to add destroyAllWindows task to the queue and delay it.

the new code would be then

import cv2 as cv

img = cv.imread('book.jpg')
cv.imshow('img', img)

cv.waitKey(0)
cv.destroyAllWindows()
cv.waitKey(1)

thanks to @AbhinavMathur comment

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文