简体   繁体   中英

OpenCV 2.4 : C API for converting cvMat to IplImage

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.

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;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM