[英]I am trying to capture video from my webcam using opencv_python
I am trying to run code to show the video output of my webcam and all I am getting is a single picture.我正在尝试运行代码来显示我的网络摄像头的视频 output,但我得到的只是一张照片。 Here is my code:这是我的代码:
import cv2
captureDevice = cv2.VideoCapture(0)
while True:
check, frame=captureDevice.read()
print(check)
print(frame)
gray=cv2.cvtColor(gray, cv2.COLOR_BGR2GRAY)
cv2.imshow('Capturing', gray)
key=cv2.waitKey(1)
if key==ord('q'):
break
captureDevice.release()
cv2.destroyAllWindows()
gray=cv2.cvtColor(gray, cv2.COLOR_BGR2GRAY)
you are using a variable gray
you would have defined elsewhere.您正在使用您会在其他地方定义的变量gray
。 Ideally this should throw error.理想情况下,这应该会引发错误。 (Try restarting your notebook and you will see) Change it to: (尝试重新启动你的笔记本,你会看到)将其更改为:
gray=cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.