[英]cv2.waitKey(0) returns None
I tried work with 我尝试与
if cv2.waitKey(0) & 0xFF == ord('q'):
break
But I kept on getting TypeError
. 但是我一直在获取TypeError
。 However, when I use either one my camera does not respond to the code. 但是,当我使用任一相机时,我的相机都不会响应该代码。
import cv2
import numpy as np
capture = cv2.VideoCapture(0)
while True:
ret, frame = capture.read()
cv2.imshow("frame", frame)
if cv2.waitKey(0) & 0xFF == ord('q'):
break
capture.release()
cv2.destroyAllWindows()
if cv2.waitKey(0) & 0xFF == ord('q'): 如果cv2.waitKey(0)和0xFF == ord('q'):
TypeError: unsupported operand type(s) for &: 'NoneType' and 'int' TypeError:&:不支持的操作数类型:“ NoneType”和“ int”
Process finished with exit code 1 流程以退出代码1完成
Although the docs state the waitkey function returns the code of the pressed key, you could pull out the value and perform a none check 尽管文档说明了waitkey函数返回了按下的键的代码,但是您可以提取该值并执行不检查
c = cv2.waitKey(0)
if c is not None and c & 0xFF == ord('q'):
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.