具有H264 CODEC的OpenCV VideoCapture [英] OpenCV VideoCapture with H264 CODEC

查看:269
本文介绍了具有H264 CODEC的OpenCV VideoCapture的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为我的项目使用新的Logitech相机c920进行对象识别.
我的相机可以支持H264编解码器,并可以显示H264 HD输出.
但是如何在下面的代码中将编解码器类型设置为H264,以将其输出为H264 DECODED STREAM 通过使用OpenCV指令.

I am using new logitech camera c920 for my project to do object recognition .
My camera can support H264 codec and can display H264 HD output.
But How I can set CODEC type as H264 in my below code to get out put as H264 DECODED STREAM by using OpenCV instruction .

我正在使用以下逻辑捕获视频:ref:此链接

I am capturing video by using below logic : ref:this link

#include "opencv2/opencv.hpp"

using namespace cv;

int main(int, char**)
{
    VideoCapture cap(0); // open the default camera
    if(!cap.isOpened())  // check if we succeeded
        return -1;

    for(;;)
    {
        Mat frame;
        cap >> frame; // get a new frame from camera
        imshow("display", frame);
        if(waitKey(30) >= 0) break;
    }
    // the camera will be deinitialized automatically in VideoCapture destructor
    return 0;
}

推荐答案

通过设置fourCC属性,您应该告诉VideoCapture您的来源是h.264.所有openCV的文档都说您将获得解码后的BGR数据.

By setting the fourCC property, you should be telling VideoCapture that your source is h.264. All the docs for openCV say that you will get decoded BGR data out though.

cap.set(CV_CAP_PROP_FOURCC, CV_FOURCC('H', '2', '6', '4'));

这篇关于具有H264 CODEC的OpenCV VideoCapture的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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