为什么在 openCV 中删除 waitKey() 不起作用? [英] Why removing waitKey() in openCV doesn't work?
本文介绍了为什么在 openCV 中删除 waitKey() 不起作用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我开始使用带有 Python 3 的 OpenCV,我有以下代码段:
I'm starting out with OpenCV with Python 3 and I have the following snippet:
import cv2
video = cv2.VideoCapture(0)
while True:
success, captured_frame = video.read()
cv2.imshow('Video', captured_frame)
pressed_key = cv2.waitKey(1) & 0xFF
if pressed_key == ord('q'):
break
video.release()
cv2.destroyAllWindows()
如果我删除 pressed_key
变量及其条件,程序会运行,但视频窗口是空白的,Windows 会尝试强制退出程序.这是为什么?
If I remove the pressed_key
variable along with its condition, the program runs but the Video window is blank and Windows attempts to force quit the program. Why is that?
推荐答案
opencv 在 waitKey 时间执行窗口渲染,因此您至少需要调用 waitKey(1) 来查看一些窗口内容.
opencv performs window rendering during waitKey times, so you will need at least a waitKey(1) call to see some window content.
这篇关于为什么在 openCV 中删除 waitKey() 不起作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文