Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to convert a Mat variable type in an IplImage variable type in OpenCV 2.0?

I am trying to rotate an image in OpenCV.

I've used this code that I found here on Stack Overflow:

Mat source(img);
Point2f src_center(source.cols/2.0, source.rows/2.0);
Mat rot_mat = getRotationMatrix2D(src_center, 40.0, 1.0);
Mat dst;
warpAffine(source, dst, rot_mat, source.size());

Once I have my dst Mat variable type filled up I would like to put it back to an IplImage variable type, any idea about how to do this?

like image 924
Spredzy Avatar asked Mar 18 '10 08:03

Spredzy


2 Answers

In the new OpenCV 2.0 C++ interface it's not really necessary to change from back and forth between Mat and IplImage, but if you want to you can use the IplImage operator:

IplImage dst_img = dst;

Note that only the IplImage header is created and the data (pixels) will be shared. For more info see the OpenCV C++ interface or the image.cpp example in the OpenCV-2.0/samples/c directory.

like image 111
jeff7 Avatar answered Nov 06 '22 15:11

jeff7


For having the whole IplImage object, I've used this code:

Mat matImage;
IplImage* iplImage;

iplImage = cvCreateImage(cvSize(640,480), IPL_DEPTH_8U, 1);
iplImage->imageData = (char *) matImage.data;

You can also copy the data instead of pointer:

memcpy(iplImage->imageData, matimage.data, 640*480);
like image 15
lumapu Avatar answered Nov 06 '22 14:11

lumapu