我试图在python中使用cv2从网络摄像头捕获数据,但是当我打印帧时,所有矩阵只包含零值。相机正在工作,它正在显示视频,没有黑屏。
这是代码
import cv2
video = cv2.VideoCapture(0)
a = 0
while True:
a = a + 1
check, frame = video.read()
print(frame)
cv2.imshow("Capturing", frame)
key = cv2.waitKey(1)
if key == ord('q'):
break
video.release()
cv2.destroyAllWindows()
我测试了你的代码,它对我有用。
我建议:
因此,请尝试将打印行更改为:
if a%100 == 0: print(frame, flush = True)