【问题标题】:Systematic offset on V4L2 framesV4L2 帧上的系统偏移
【发布时间】:2016-10-30 23:04:52
【问题描述】:

我正在使用 V4L2 API 从 UVC 设备抓取帧。我想通过计算帧的时间戳和当前时钟时间之间的偏移量来测量曝光时间。这是我正在使用的代码:

/* Control code snipped */
struct v4l2_buffer buf = {0}
buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
buf.memory = V4L2_MEMORY_MMAP;
ioctl(fd, VIDIOC_DQBUF, &buf);

switch( buf.flags & V4L2_BUF_FLAG_TIMESTAMP_MASK )
{
    case V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC:
    {
        struct timespec uptime = {0};
        clock_gettime(CLOCK_MONOTONIC,&uptime);

        float const secs =
            (buf.timestamp.tv_sec - uptime.tv_sec) +
            (buf.timestamp.tv_usec - uptime.tv_nsec/1000.0f)/1000.0f;

        if( V4L2_BUF_FLAG_TSTAMP_SRC_SOE == (buf.flags & V4L2_BUF_FLAG_TSTAMP_SRC_MASK) )
            printf("%s: frame exposure started %.03f seconds ago\n",__FUNCTION__,-secs);
        else if( V4L2_BUF_FLAG_TSTAMP_SRC_EOF == (buf.flags & V4L2_BUF_FLAG_TSTAMP_SRC_MASK) )
            printf("%s: frame finished capturing %.03f seconds ago\n",__FUNCTION__,-secs);
        else printf("%s: unsupported timestamp in frame\n",__FUNCTION__);

        break;
    }

    case V4L2_BUF_FLAG_TIMESTAMP_UNKNOWN:
    case V4L2_BUF_FLAG_TIMESTAMP_COPY:
    default:
        printf("%s: no usable timestamp found in frame\n",__FUNCTION__);
}

使用VIDIOC_S_CTRL 设置曝光时间为 1 秒时返回的示例:

read_frame: frame exposure started 28.892 seconds ago
read_frame: frame exposure started 28.944 seconds ago
read_frame: frame exposure started 28.895 seconds ago
read_frame: frame exposure started 29.037 seconds ago

我在SRC_SOE 时间戳和单调时钟之间得到了奇怪的 30 秒偏移,其中 1 秒曝光焊接。V4L2/UVC 时间戳应该是根据 ktime_get_ts() 的结果计算的.知道我做错了什么吗?

这在 Linux 4.4 Gentoo 系统上运行。网络摄像头是 DMK21AU04.AS,被识别为标准 UVC 设备。

【问题讨论】:

    标签: linux v4l2 uvc


    【解决方案1】:

    事情是……

    1 秒 = 1000 毫秒,
    1 毫秒 = 1000 微秒,
    1 us = 1000ns。

    所以...

    应该是……

    float const secs =
            (buf.timestamp.tv_sec - uptime.tv_sec) +
            (buf.timestamp.tv_usec - uptime.tv_nsec/1000.0f)/1000000.0f;
    

    【讨论】:

    • 谢谢@TallFurryMan,实际上你的代码 sn-p 对我很有帮助...
    • 我不敢相信我已经盯着答案看了这么久却没有看到它:)
    猜你喜欢
    • 2022-07-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多