Ask Your Question
0

Why does this rotate method give the image dead space? OpenCV

asked 2014-04-18 00:20:03 -0600

Luek gravatar image

I am using this method to rotate a cvMat, whenever I run it I get back a rotated image however there is a lot of deadspace below it.

void rotate(cv::Mat& src, double angle, cv::Mat& dst)
{
    int len = std::max(src.cols, src.rows);
    cv::Point2f pt(len/2., len/2.);
    cv::Mat r = cv::getRotationMatrix2D(pt, angle, 1.0);

    cv::warpAffine(src, dst, r, cv::Size(len, len));

}

When given this image:

enter image description here

I get this image:

enter image description here

The image has been rotated but as you can see some extra pixels have been added, how can I only rotate the original image and not add any extra pixels?

Method call:

rotate(src, skew, res); res being dst.

edit retag flag offensive close merge delete

Comments

FYI: you can also use cv::BORDER_REPLICATE to make the corners white.

GrumbleLion gravatar imageGrumbleLion ( 2014-04-28 15:39:19 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
2

answered 2014-04-18 01:30:03 -0600

Haris gravatar image

updated 2014-04-18 01:31:07 -0600

The fourth parameter your are passing to wrapAffine is the size of destination image after wrap, and you are passing it like Size(len, len) where len = std::max(src.cols, src.rows). So just change the wrapAffine call to

cv::warpAffine(src, dst, r, src.size());

Also see the answer here might be helpful.

edit flag offensive delete link more

Question Tools

Stats

Asked: 2014-04-18 00:20:03 -0600

Seen: 515 times

Last updated: Apr 18 '14