OpenCV USB 摄像头在 Raspberry Pi 4 32 位上不工作

OpenCV USB-camera does not work on Raspberry Pi 4 32-bit

当我尝试使用 opencv 和 python 开始视频捕获时,它根本无法加载。没有显示任何问题,没有 return 任何东西。没有!!!

代码是最简单的:

import cv2
import sys

video_capture = cv2.VideoCapture(0)

while True:
   ret, frame = video_capture.read()

   cv2.imshow('Video', frame)

   if cv2.waitKey(1) & 0xFF == ord('q'):
       break

video_capture.release()
cv2.destroyAllWindows()

这是运行这个程序

的结果

如果我 运行 逐行编码,这就是卡住的地方

如果我在执行最后一行时按 Ctrl+C,它会告诉我:

Trying to dispose element pipeline0, but it is in PAUSED instead of the NULL state.

You need to explicitly set elements to the NULL state before

dropping the final reference, to allow them to clean up.

This problem may also be caused by a refcounting bug in the

application or some element.

也许不是真正的解决方案,但可以尝试 0 努力的方法是像这样指定视频后端:

video_capture = cv2.VideoCapture(0, CAP_V4L2)