首页 > 解决方案 > USB 网络摄像头和可用格式

问题描述

我有一个 ELP USB 相机。可用的格式有:

$ v4l2-ctl --list-formats-ext -d /dev/video1
ioctl: VIDIOC_ENUM_FMT
Type: Video Capture

[0]: 'MJPG' (Motion-JPEG, compressed)
    Size: Discrete 1920x1080
        Interval: Discrete 0.033s (30.000 fps)
    Size: Discrete 1280x720
        Interval: Discrete 0.017s (60.000 fps)
    Size: Discrete 1024x768
        Interval: Discrete 0.033s (30.000 fps)
    Size: Discrete 640x480
        Interval: Discrete 0.008s (120.101 fps)
    Size: Discrete 800x600
        Interval: Discrete 0.017s (60.000 fps)
    Size: Discrete 1280x1024
        Interval: Discrete 0.033s (30.000 fps)
    Size: Discrete 320x240
        Interval: Discrete 0.008s (120.101 fps)
[1]: 'YUYV' (YUYV 4:2:2)
    Size: Discrete 1920x1080
        Interval: Discrete 0.167s (6.000 fps)
    Size: Discrete 1280x720
        Interval: Discrete 0.111s (9.000 fps)
    Size: Discrete 1024x768
        Interval: Discrete 0.167s (6.000 fps)
    Size: Discrete 640x480
        Interval: Discrete 0.033s (30.000 fps)
    Size: Discrete 800x600
        Interval: Discrete 0.050s (20.000 fps)
    Size: Discrete 1280x1024
        Interval: Discrete 0.167s (6.000 fps)
    Size: Discrete 320x240
        Interval: Discrete 0.033s (30.000 fps)

假设我想使用 MJPG 1280x720 @ 20fps,甚至像 1280x720 @ 18fps 这样奇怪的东西。

这个答案说:

v4l2 仅支持列出的格式,其他任何内容都需要用户编码,并且很少提供 RGB,尽管几乎所有 CCD 都在 Bayer RGGB [...]

设置自定义分辨率和帧率的方法是什么?更愚蠢的问题,有没有办法用这些 USB 相机控制快门时间?

编辑:我正在使用 Python。OpenCV 根本无法访问相机,但它可以与 Webcamoid 软件配合使用。

标签: opencvvideocamerausbcodec

解决方案


我只是将您从相机采样的频率更改为您想要的帧速率。

如果我们看一下 MJPEG:

尺寸:离散 1280x720 间隔:离散 0.017s (60.000 fps)

只需每秒从该流中读取 20 次(基本上每第三帧获取一次),或每秒读取 18 次(每第三/第四帧获取一次)。

在 HTML 中,您可以使用 getUserMedia 执行此操作:

设置宽度、高度和帧率的变量:

var constraints = { audio: {sampleRate: audiobitrate, 
                            echoCancellation: true},
    video:{
        width: { min: 100, ideal: width, max: 1920 },
        height: { min: 100, ideal: height, max: 1080 },
        frameRate: {ideal: framerate}
    }
};
console.log(constraints);
navigator.mediaDevices.getUserMedia(constraints).then(function(stream) {

// do your thing... }

此代码来自我构建的直播应用程序(第 273 行):https ://github.com/dougsillars/browserLiveStream/blob/master/public/index.html


推荐阅读