Python视频捕获(0)我的相机坏了
这是我的密码:Python视频捕获(0)我的相机坏了,python,opencv,video-capture,Python,Opencv,Video Capture,这是我的密码: import numpy as np import cv2 cap = cv2.VideoCapture(0) while(True): # Capture frame-by-frame ret, frame = cap.read() # Our operations on the frame come here gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY) # Display the resulting frame cv2
import numpy as np
import cv2
cap = cv2.VideoCapture(0)
while(True):
# Capture frame-by-frame
ret, frame = cap.read()
# Our operations on the frame come here
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
# Display the resulting frame
cv2.imshow('frame',gray)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
# When everything done, release the capture
cap.release()
cv2.destroyAllWindows()
我这样写代码,并试图打开我的相机,但相机图像看起来像截图
停止工作屏幕截图有什么想法吗?原因是什么?是缩进问题。
请尝试以下代码:
import numpy as np
import cv2
cap = cv2.VideoCapture(0)
while(True):
# Capture frame-by-frame
ret, frame = cap.read()
# Our operations on the frame come here
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
# Display the resulting frame
cv2.imshow('frame',gray)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
# When everything done, release the capture
cap.release()
cv2.destroyAllWindows()
提供适当的缩进,以便程序正常运行。按“q”停止该程序。有人有什么想法吗?您确定使用了正确的网络摄像头吗?你的设置中有不止一个吗?@george.adams1我绝对肯定,因为c#emgucv工作正常,但同样的问题仍然存在。你看过屏幕截图了吗?检查你的网络摄像头是否工作正常。(内置网络摄像头)用于usb网络摄像头设置“cap=cv2.VideoCapture(1)”我的网络摄像头工作出色,我在c#emgucv上测试过。cap=cv2。视频捕获(1)我已测试,但问题仍然存在。您的网络摄像头是内置的还是usb连接的?