显示没有waitKey的图像 [英] Displaying image without waitKey
问题描述
此 Python 代码以全屏方式显示图像:
This Python code displayed an image in full screen:
blank_image = cv2.imread('blank.jpg')
cv2.namedWindow("bw", cv2.WND_PROP_FULLSCREEN)
cv2.setWindowProperty("bw", cv2.WND_PROP_FULLSCREEN, cv2.cv.CV_WINDOW_FULLSCREEN)
cv2.imshow("bw", blank_image)
cv2.waitKey(0)
问题是代码将在没有键盘的 Linux 机器上运行.调用waitKey就意味着要等到按键事件发生才会进行UI处理,因此矛盾.
The problem is the code is going to run on a Linux machine without keyboard. Calling waitKey means the UI processing will not be done until a key event occurs, and thus the contradiction.
那除了waitKey还有什么办法吗?
Is there any way beside the waitKey, then?
推荐答案
只是为了澄清:来自 docs 你可以看到
Just to clarify: from the docs you can see that
Python: cv2.waitKey([delay]) → retval
Python: cv2.waitKey([delay]) → retval
函数waitKey无限等待一个按键事件(当delay <= 0 ) 或延迟毫秒,当它为正时.
The function waitKey waits for a key event infinitely (when delay <= 0 ) or for delay milliseconds, when it is positive.
如果您使用 delay = 0
,那么您的程序将无限等待关键事件,从而阻止执行.正如@Miki 所说,您可以使用 delay = 1
,这样 waitKey
就不会阻塞.
If you use the delay = 0
, then your program waits for a key event infinitely, blocking the execution. As @Miki said, you can use delay = 1
, so that waitKey
won't block.
这篇关于显示没有waitKey的图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!