# Rotate image(mat or iplimage) with size conversion [closed]

I have image at IplImage (there is not problem to convert it to Mat). I have to rotate my image. I have image:

IplImage* mg


My method for rotate:

IplImage *rotateImage2(const IplImage *src, float angleDegrees)
{
// Create a map_matrix, where the left 2x2 matrix
// is the transform and the right 2x1 is the dimensions.
float m[6];
CvMat M = cvMat(2, 3, CV_32F, m);
int w = src->width;
int h = src->height;
float angleRadians = angleDegrees * ((float)CV_PI / 180.0f);
m[3] = -m[1];
m[4] = m[0];
m[2] = w*0.5f;
m[5] = h*0.5f;

// Make a spare image for the result
CvSize sizeRotated;
sizeRotated.width = cvRound(w);
sizeRotated.height = cvRound(h);

// Rotate
IplImage *imageRotated = cvCreateImage(sizeRotated,
src->depth, src->nChannels);

// Transform the image

return imageRotated;
}


But after rotate my new image have incorrect resolution. Rotation occurs in this resolution, but my new image have to take new resolution. Test image(original image - center, left image - rotated by my method, right image - rotated by system service): U can see, that my new image crop hat of man, and new image have bigger width. How i could rotate my image without this problem?

edit retag reopen merge delete

### Closed for the following reason question is not relevant or outdated by sturkmen close date 2017-08-22 11:34:07.005302

Sort by ยป oldest newest most voted

Drop the old C interface. Use the new one and especially the getRotationMatrix2D function. Your code will be much shorter. Have a look for an example here: http://opencv-code.com/quick-tips/how-to-rotate-image-in-opencv/#more-220

more

Official site

GitHub

Wiki

Documentation