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?
For having the whole
IplImage
object, I've used this code:You can also copy the data instead of pointer:
Norman in his blog describes the following (Although it is not 2.0, it should apply to your problem.):
To transform from CvMat to IplImage, Use function:
The function cvGetImage returns image header for the input array that can be matrix - CvMat*, or image - IplImage*. In the case of image the function simply returns the input pointer. In the case of CvMat* it initializes image_header structure with parameters of the input matrix. Usage:
In later versions of OpenCV 2.4 and above, we can convert it simply by
In the new OpenCV 2.0 C++ interface it's not really necessary to change from back and forth between
Mat
andIplImage
, but if you want to you can use theIplImage
operator: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 theOpenCV-2.0/samples/c
directory.