我需要一个实时流摄像头的python脚本,我想使用键盘对流进行灰度化,但我不能,每次我运行打击代码流时都会更改为灰度,但一秒钟后它会恢复正常,请帮我解决这个问题
import cv2
cap = cv2.VideoCapture(0)
while True:
ret, frame = cap.read()
gray=cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
c = cv2.waitKey(1)
if c & 0xFF == ord('q'):
break
elif c & 0xFF == ord('3'):
frame=gray
cv2.imshow('a',frame)
cap.release()
cv2.destroyAllWindows()
我需要使用键盘更改它