Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OpenCV VideoCapture with H264 CODEC

Tags:

opencv

codec

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;
}
like image 817
Ashwin Avatar asked Oct 22 '25 14:10

Ashwin


1 Answers

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'));
like image 151
Paul Gregoire Avatar answered Oct 26 '25 02:10

Paul Gregoire