简体   繁体   English

cv2.waitKey(0) 阻塞程序

[英]cv2.waitKey(0) blocks the program

Here is a simple script:这是一个简单的脚本:

import cv2

img = cv2.imread("img.png", 0)
cv2.imshow("Test", img)
print("Before")
cv2.waitKey(0)
print("After")

After closing the Test window, the output of terminal was like:关闭测试window 后,终端的 output 是这样的:

$ python test.py $ python test.py
Before

It seems that cv2.waitKey(0) blocks the program and I cannot even kill the process by typing ctrl+c in the terminal.似乎cv2.waitKey(0)阻止了程序,我什至无法通过在终端中键入ctrl+c来终止该进程。 What's wrong with it?它出什么问题了?

PS: It works properly before but today there is some system upgrade being done and this kind of issue happened. PS:之前可以正常使用,但是今天升级了一些系统,出现了这种问题。 I'm using ubuntu 18.04.我正在使用 ubuntu 18.04。

waitKey() is supposed to break/return once all windows have been closed, and also return immediately if no windows are currently open. waitKey()应该在所有 windows 都已关闭后中断/返回,如果当前没有 windows 处于打开状态,则也立即返回。 This is regardless of the desired amount of delay .这与所需的delay量无关。

On Windows 10, I can't reproduce what you describe.在 Windows 10 上,我无法重现您所描述的内容。 That is to say, it's probably specific to your environment.也就是说,它可能特定于您的环境。

Your described behavior is probably a bug due to bad interaction with a window manager/GUI toolkit.您描述的行为可能是由于与 window 管理器/GUI 工具包的不良交互导致的错误。

Please check https://github.com/opencv/opencv/labels/category%3A%20highgui-gui for any obvious previous reporting.请检查https://github.com/opencv/opencv/labels/category%3A%20highgui-gui是否有任何明显的先前报告。

Before opening a new bug, make sure it's reproducible and comes with a description of the environment that is required to reproduce it.在打开一个新错误之前,请确保它是可重现的,并附有重现它所需的环境描述。 That includes all versions of everything you think is relevant, including OpenCV's version.这包括您认为相关的所有版本,包括 OpenCV 的版本。

After checking issues of opencv, I do find the same problem that has already been posted: https://github.com/opencv/opencv/issues/20822 .检查 opencv 的问题后,我确实发现了已经发布的相同问题: https://github.com/opencv/opencv/issues/20822

It is a bug due to the Qt Gui backend and the issue is still open.这是由于 Qt Gui 后端导致的错误,问题仍然存在。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM