OpenCV 2.4 : C API for converting cvMat to IplImage

577 views Asked by At

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

There are 1 answers

0
Avis On

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;