Ask Your Question
0

How to get raw data using OpenCV APIs

asked 2016-06-21 00:40:36 -0600

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

edit retag flag offensive close merge delete

Comments

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

berak gravatar imageberak ( 2016-06-21 00:42:13 -0600 )edit

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

neha_new2OpenCV gravatar imageneha_new2OpenCV ( 2016-06-21 00:46:26 -0600 )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 ( 2016-06-21 00:50:52 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
0

answered 2016-06-21 01:05:21 -0600

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;
    }
}
edit flag offensive delete link more

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 ( 2016-06-21 01:54:32 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2016-06-21 00:40:36 -0600

Seen: 5,490 times

Last updated: Jun 21 '16