0
votes

I'm having an YUYV image buffer in cvMat object (snippet shown below). I had to convert this cvMat object to IplImage for color conversion.

CvMat cvmat = cvMat(480, 640, CV_8UC2, yuyv_buff);

I tried the below options to convert this cvmat object to IplImage object (src: https://medium.com/@zixuan.wang/mat-cvmat-iplimage-2f9603b43909 ).

//cvGetImage()
CvMat M;
IplImage* img = cvCreateImageHeader(M.size(), M.depth(), M.channels());
cvGetImage(&M, img); //Deep Copy

//Or
CvMat M;
IplImage* img = cvGetImage(&M, cvCreateImageHeader(M.size(), M.depth(), M.channels()));

//cvConvert()
CvMat M;
IplImage* img = cvCreateImage(M.size(), M.depth(), M.channels());
cvConvert(&M, img); //Deep Copy

But nothing worked. cvGetImage(), cvConvert() expects cvArr* as input. Passing &cvmat to them throws exception.

Is there any other way to convert an CvMat object to IplImage object in OpenCV 2.4 ?

Note: I cannot use C++ API or any other version of OpenCV. I'm limited to use only OpenCV 2.4

Edit 1: My objective is to convert this YUYV buffer to an RGB image object.

1
I've never tried to convert backwards, but I suspect that M.data will give you the array you need. - beaker
Tried passing M.data, still OpenCV throws exception. terminate called after throwing an instance of 'cv::Exception'. what(): /build/<path>/modules/core/src/array.cpp:2791: error: (-206) in function cvGetImage - Avis
Instead of creating cvMat, i was able to create an IplImage directly from the yuyv image buffer like below: IplImage* frame = cvCreateImage(cvSize(640,480), IPL_DEPTH_8U, 2); frame->imageData=(char*)yuyv_buffer; - Avis

1 Answers

0
votes

Instead of creating cvMat, I was able to create an IplImage directly from the yuyv image buffer like below:

IplImage* frame = cvCreateImage(cvSize(640,480), IPL_DEPTH_8U, 2); 
frame->imageData=(char*)yuyv_buffer;