OpenCV VideoCapture with H264 CODEC

╄→гoц情女王★ 提交于 2019-12-02 11:31:26

问题


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 .

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;
}

回答1:


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'));


来源:https://stackoverflow.com/questions/27392455/opencv-videocapture-with-h264-codec

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!