Ask Your Question
0

How to get raw data using OpenCV APIs

asked Jun 21 '16

neha_new2OpenCV gravatar image

Hi all

When I am using cvCaptureFromCAM and cvQueryFrame(), it creates image frames in RGB24 format. My Logitech camera generates YUV image. My query is How to disable this YUV to RGB conversion in the OpenCV? I don't want the image in the RGB format. Neither I want to convert the image using OpenCV APIs to YUV in the code.

All I want is the raw image generated by the camera as-is. Is that possible in OpenCV? If yes then kindly guide me.

Thanks Neha

Preview: (hide)

Comments

unrelated, but please stop using the deprecated c-api !

berak gravatar imageberak (Jun 21 '16)edit

@berak - Ok. Are you suggesting to use capture.open and capture.grab()?

neha_new2OpenCV gravatar imageneha_new2OpenCV (Jun 21 '16)edit
1

You could try to set CV_CAP_PROP_CONVERT_RGB property of your camera to false. However this not seems to work everytime, but maybe it will work for you.

Missing gravatar imageMissing (Jun 21 '16)edit

1 answer

Sort by » oldest newest most voted
0

answered Jun 21 '16

berak gravatar image

first, please use cv::VideoCapture (c++), not the deprecated c-api calls.

then, you can try to set properties on the capture, like CAP_MODE_YUVY but none of them are guaranteed to succed., it all depends on your os / hardware / driver mix.

#include "opencv2/opencv.hpp"
using namespace cv;

#include <iostream>
using namespace std;

int main()
{
    VideoCapture cap(0);

    bool ok = cap.set(CAP_PROP_CONVERT_RGB, 0);
    cerr << ok << endl;


    while(cap.isOpened())
    {
        Mat f;
        cap >> f;
        if (f.empty())
        {
            cerr << "."; // older webcams might need some "warmup" ..
            continue;
        }
        imshow("ocv",f);
        if (waitKey(10)==27) break;
    }
}
Preview: (hide)

Comments

With the above code, the height and width coming out is 1 and 341333 respectively. The values are not correct? Isn't it?

neha_new2OpenCV gravatar imageneha_new2OpenCV (Jun 21 '16)edit

Question Tools

1 follower

Stats

Asked: Jun 21 '16

Seen: 5,551 times

Last updated: Jun 21 '16