在 Ubuntu 20.04 上启用摄像头视频捕捉

在 Ubuntu 20.04 上启用摄像头视频捕捉

Ubuntu 20.04 有一个 ARM64 版本,可以在 Raspberry Pi 4 上开箱即用,而且确实如此。但是,我不知道如何从使用带状电缆连接的本机摄像头获取视频。我使用 ROS2/OpenCV 访问摄像头,如下所示:

import cv2 as cv
cap = cv.VideoCapture(10)
print( cap.isOpened() )

我总是得到False。我输入设备编号10VideoCapture()因为没有/dev/video0,只有等/dev/video10/dev/video11是否需要以某种方式安装相机才能工作?

以下是我从代码中得到的全部错误:

[ WARN:0] global ../modules/videoio/src/cap_gstreamer.cpp (1758) handleMessage OpenCV | GStreamer warning: Embedded video playback halted; module v4l2src0 reported: Device '/dev/video10' is not a capture device.
[ WARN:0] global ../modules/videoio/src/cap_gstreamer.cpp (888) open OpenCV | GStreamer warning: unable to start pipeline
[ WARN:0] global ../modules/videoio/src/cap_gstreamer.cpp (480) isPipelinePlaying OpenCV | GStreamer warning: GStreamer: pipeline have not been created
[ WARN:0] global ../modules/videoio/src/cap_v4l.cpp (887) open VIDEOIO(V4L2:/dev/video10): can't open camera by index

关键点似乎是:Device '/dev/video10' is not a capture device。那么我如何获得捕获设备?

所以我认为关键问题是如何让 Raspberry Pi 创建一个/dev/video0指向相机的文件。

答案1

如果你查看 RPi 上的 dmesg,那么你应该会看到类似这样的内容:

$ dmesg
...
[    3.892570] videodev: Linux video capture interface: v2.00
[    3.924273] snd_bcm2835: module is from the staging directory, the quality is unknown, you have been warned.
[    3.944425] bcm2835_audio bcm2835_audio: card created with 4 channels
[    3.954828] bcm2835_audio bcm2835_audio: card created with 4 channels
[    3.994725] bcm2835_mmal_vchiq: module is from the staging directory, the quality is unknown, you have been warned.
[    3.994784] bcm2835_mmal_vchiq: module is from the staging directory, the quality is unknown, you have been warned.
[    4.001545] bcm2835_mmal_vchiq: module is from the staging directory, the quality is unknown, you have been warned.
[    4.027570] bcm2835_v4l2: module is from the staging directory, the quality is unknown, you have been warned.
[    4.028170] bcm2835_codec: module is from the staging directory, the quality is unknown, you have been warned.
[    4.029063] bcm2835_isp: module is from the staging directory, the quality is unknown, you have been warned.
[    4.055371] bcm2835-isp bcm2835-isp: Device node output[0] registered as /dev/video13
[    4.055899] bcm2835-isp bcm2835-isp: Device node capture[0] registered as /dev/video14
[    4.056430] bcm2835-isp bcm2835-isp: Device node capture[1] registered as /dev/video15
[    4.059344] bcm2835-isp bcm2835-isp: Device node stats[2] registered as /dev/video16
[    4.059378] bcm2835-isp bcm2835-isp: Register output node 0 with media controller
[    4.059398] bcm2835-isp bcm2835-isp: Register capture node 1 with media controller
[    4.059414] bcm2835-isp bcm2835-isp: Register capture node 2 with media controller
[    4.059427] bcm2835-isp bcm2835-isp: Register capture node 3 with media controller
[    4.059529] bcm2835-codec bcm2835-codec: Device registered as /dev/video10
[    4.059569] bcm2835-codec bcm2835-codec: Loaded V4L2 decode
[    4.068348] bcm2835-codec bcm2835-codec: Device registered as /dev/video11
[    4.068389] bcm2835-codec bcm2835-codec: Loaded V4L2 encode
[    4.071323] bcm2835-isp bcm2835-isp: Loaded V4L2 bcm2835-isp
[    4.078793] bcm2835-codec bcm2835-codec: Device registered as /dev/video12
[    4.078836] bcm2835-codec bcm2835-codec: Loaded V4L2 isp
...

这告诉我,有几个视频设备已初始化 - 一些用于输入/捕获,一些用于输出,一些作为 DSP 用于编码/解码(RPi4 上的 H.264,以及早期 RPi 上的 MPEG2/MPEG4/VC1)。

我建议你尝试使用上面提到的“设备节点捕获[x]”设备,在我的情况下是/dev/video14 或...15(RPi4 有 2 个摄像头接口,如上所述“ 这里)。

答案2

应该获得/dev/video0 的部分答案:

  1. 编辑文件/boot/firmware/config.txt添加两行:
     start_x=1
     gpu_mem=128
  1. 保存文件并重新启动
  2. 在终端中运行 sudo apt-get update
  3. 在同一个终端中,运行sudo apt-get upgrade

这只是部分答案,因为诸如 Open CV 捕获或其他读取相机的方法对我来说仍然不起作用。之后我收到 GStreamer 警告和错误。

相关内容