使用cv2从摄像机捕获视频会打印出充满零的矩阵

问题描述 投票:0回答:1

我试图在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()

This is how the output looks like

python video-capture cv2
1个回答
0
投票

我测试了你的代码,它对我有用。

我建议:

  • 每n打印一帧,例如(100)
  • 冲洗打印件,以便在捕获时可以看到框架的打印件

因此,请尝试将打印行更改为:

if a%100 == 0: print(frame, flush = True)
© www.soinside.com 2019 - 2024. All rights reserved.