Ask Your Question
0

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

asked 2014-05-20 14:15:18 -0500

Igoen gravatar image

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[0] = (float)(cos(angleRadians));
        m[1] = (float)(sin(angleRadians));
        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
        cvGetQuadrangleSubPix(src, imageRotated, &M);

        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): image description 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 flag offensive 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

1 answer

Sort by ยป oldest newest most voted
1

answered 2014-05-21 15:54:10 -0500

Witek gravatar image

updated 2014-05-21 15:55:03 -0500

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

edit flag offensive delete link more

Question Tools

Stats

Asked: 2014-05-20 14:15:18 -0500

Seen: 2,563 times

Last updated: May 21 '14