使用openCV 2.4.3从Logitech C920捕获30fps的1080p [英] Capturing 1080p at 30fps from logitech c920 with openCV 2.4.3

查看:230
本文介绍了使用openCV 2.4.3从Logitech C920捕获30fps的1080p的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从OpenCV中的Logitech C920捕获视频流.使用Labview,我可以以30fps 1080p的速度访问MJPG流.在opencv中,我只能使用5fps或640x480.

I'm trying to capture the video stream off of my Logitech C920 in OpenCV. With Labview I can access an MJPG stream at 30fps 1080p. In opencv I am limited to either 5fps or 640x480.

以下是与相机设置有关的代码:

Here is the code relevant to the camera settings:

this->camRef.set(CV_CAP_PROP_FRAME_WIDTH, 1920);
this->camRef.set(CV_CAP_PROP_FRAME_HEIGHT, 1080);
this->camRef.set(CV_CAP_PROP_FOURCC,CV_FOURCC('M','J','P','G'));

这些全部返回1,但是我得到了5PPS的1080p流,它对应于YUY2流.
如果我添加以下行:

These all return 1, yet I get a 5fps stream of 1080p which corresponds to the YUY2 stream.
If I add the following line:

this->camRef.set(CV_CAP_PROP_FPS, 30);

这将返回0. 我在640x480分辨率下获得了30 fps的流.对我来说,似乎不接受MJPG设置,但我不知道该怎么做或如何解决.

This returns 0. I get a 30 fps stream at 640x480. To me it looks like the MJPG setting isn't be accepted but I don't know what to do or how to fix that.

以下内容使程序崩溃.

 this->camRef.read(this->image);
 std::cout<< this->camRef.get(CV_CAP_PROP_FOURCC)                            << std::endl;
 std::cout<< this->camRef.set(CV_CAP_PROP_FRAME_WIDTH, config.width)         << std::endl;
 std::cout<< this->camRef.set(CV_CAP_PROP_FRAME_HEIGHT, config.height)       << std::endl;
 std::cout<< this->camRef.set(CV_CAP_PROP_FOURCC,CV_FOURCC('M','J','P','G')) << std::endl;
 std::cout<< this->camRef.get(CV_CAP_PROP_FOURCC)                            << std::endl;

然后在我的运行代码中,我有以下内容:

Then in my run code I have the following:

void camera::run()
{
    while(true)
    {
        if(this->camRef.read(this->image) == 0)
        {
           if(this->capture)
            {
                cv::imwrite(fileName,this->image);
                this->count++;
            }
        }
        msleep(15);
    }
}

解决方案是在设置相机高度和宽度之前先设置fourCC编解码器.

Solution is to set the fourCC codec before setting camera height and width.

推荐答案

由于帖子的作者已经找到了解决方案,但没有将其添加为答案,因此我将解决方案放在这里.

As the author of the post already found the solution but didn't add it as an answer I will put the solution here.

您必须先设置编解码器,然后再设置所需的分辨率:

You have to set the codec before you set the wanted resolution:

this->camRef.set(CV_CAP_PROP_FOURCC,CV_FOURCC('M','J','P','G'));
this->camRef.set(CV_CAP_PROP_FRAME_WIDTH, 1920);
this->camRef.set(CV_CAP_PROP_FRAME_HEIGHT, 1080);

这篇关于使用openCV 2.4.3从Logitech C920捕获30fps的1080p的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆