0

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.

Avis
  • 988
  • 2
  • 11
  • 31
  • I've never tried to convert backwards, but I suspect that `M.data` will give you the array you need. – beaker Mar 19 '18 at 18:24
  • Tried passing M.data, still OpenCV throws exception. `terminate called after throwing an instance of 'cv::Exception'. what(): /build//modules/core/src/array.cpp:2791: error: (-206) in function cvGetImage` – Avis Mar 20 '18 at 00:55
  • 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 Mar 20 '18 at 01:51

1 Answers1

0

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
  • 988
  • 2
  • 11
  • 31