使用OPENCV(c ++)从网络摄像头获取YUYV数据

时间:2018-08-06 10:20:16

标签: c++ opencv

这个问题已经被蜜蜂问了很多,但是我找不到它可以接受的/有效的答案。

我有一个摄像头,根据下面的v4l2-ctl命令的结果,可以将帧输出为YUYV和MJPG。

List<String> match = list
            .stream()
            .filter(item -> item.getProperty == "match")
            .collect(Collectors.toList());

if (match != null && !match.isEmpty()) {
    //handle seldom match
}

我希望我的c ++应用程序通过执行以下操作使用opencv读取未压缩(YUYV)图像:

v4l2-ctl --list-formats-ext
ioctl: VIDIOC_ENUM_FMT
    Index       : 0
    Type        : Video Capture
    Pixel Format: 'YUYV'
    Name        : YUYV 4:2:2
        Size: Discrete 640x480
            Interval: Discrete 0.033s (30.000 fps)
        Size: Discrete 320x180
            Interval: Discrete 0.033s (30.000 fps)
        Size: Discrete 320x240
            Interval: Discrete 0.033s (30.000 fps)
        Size: Discrete 424x240
            Interval: Discrete 0.033s (30.000 fps)
        Size: Discrete 640x360
            Interval: Discrete 0.033s (30.000 fps)
        Size: Discrete 848x480
            Interval: Discrete 0.033s (30.000 fps)
        Size: Discrete 960x540
            Interval: Discrete 0.033s (30.000 fps)
        Size: Discrete 1280x720
            Interval: Discrete 0.033s (30.000 fps)
        Size: Discrete 1600x1200
            Interval: Discrete 0.033s (30.000 fps)
        Size: Discrete 1920x1080
            Interval: Discrete 0.033s (30.000 fps)
        Size: Discrete 2592x1944
            Interval: Discrete 0.042s (24.000 fps)
        Size: Discrete 3264x2448
            Interval: Discrete 0.067s (15.000 fps)

    Index       : 1
    Type        : Video Capture
    Pixel Format: 'MJPG' (compressed)
    Name        : Motion-JPEG
        Size: Discrete 640x480
            Interval: Discrete 0.033s (30.000 fps)
        Size: Discrete 320x180
            Interval: Discrete 0.033s (30.000 fps)
        Size: Discrete 320x240
            Interval: Discrete 0.033s (30.000 fps)
        Size: Discrete 424x240
            Interval: Discrete 0.033s (30.000 fps)
        Size: Discrete 640x360
            Interval: Discrete 0.033s (30.000 fps)
        Size: Discrete 848x480
            Interval: Discrete 0.033s (30.000 fps)
        Size: Discrete 960x540
            Interval: Discrete 0.033s (30.000 fps)
        Size: Discrete 1280x720
            Interval: Discrete 0.033s (30.000 fps)
        Size: Discrete 1600x1200
            Interval: Discrete 0.033s (30.000 fps)
        Size: Discrete 1920x1080
            Interval: Discrete 0.033s (30.000 fps)
        Size: Discrete 2592x1944
            Interval: Discrete 0.042s (24.000 fps)
        Size: Discrete 3264x2448
            Interval: Discrete 0.067s (15.000 fps)

此代码导致图像为空(test.jpg是一个0字节的文件),并且一旦我想使用框架,代码便崩溃了。

我使用

做了另一个试验
VideoCapture cap(0);   //<---- camera
if (cap.isOpened())
{
    cap.set(CAP_PROP_CONVERT_RGB, 0);
    cap>>frame;
    imwrite("test.jpg", frame);
     .
     .
     .
}

但是我最终得到了警告

cap.set(CV_CAP_PROP_MODE, CV_CAP_MODE_YUYV);

它使用了MJPG图片(当我使用opencv获得四个抄送时)

有没有办法从相机获取未压缩的图像?

0 个答案:

没有答案