2
votes

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
you can use imencode to encode to memory or create a VideoWriter class with a FOURCC code. But many precompiled openCV distributions dont support H.264 encoding as far as I know, so you might have to compile it on your own with x264 libs enabled.Micka
ah... read your question again... I'm quite sure that cap >> frame already delivers DECODED images. Do you want to encode it or do you want to get the encoded stream directly from camera? I dont think that is possible with openCV functions, maybe your camera drivers give you fitting methods?!?Micka
Thanks Micka for your replay .I came to know the same now that cap>>frame is internally decoding by using FFMPEG codec .So not required to explicitly use the other codec .Do you know how to capture the raw data from Logitech camera and stored inside the normal bitstream ??Ashwin
Sorry no experience with those camsMicka

1 Answers

3
votes

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