通过c ++在opencv中旋转图像而不缩放图像

时间:2017-04-21 10:13:10

标签: c++ opencv scale image-rotation

我通过c ++使用OpenCV 2.4。我有一个二进制图像,使用minAreaRect函数来找到它的角度,如:

    RotatedRect BodyRec = minAreaRect(PointsOfbinaryImage);
    angle=BodyRec.angle;

    if (angle < -45.)
        angle += 90.;
        result.Angle=angle;

    //calculate Center 
    result.Center=BodyRec.center;

现在,我想在不缩放图像的情况下旋转图像。 我使用这段代码:

    // get rotation matrix for rotating the image around its center
Point2f center22(RGBsrc.cols/2.0, RGBsrc.rows/2.0);
Mat rot = getRotationMatrix2D(center22, result.Angle, 1.0);
// determine bounding rectangle
Rect bbox = RotatedRect(center22,RGBsrc.size(), result.Angle).boundingRect();
// adjust transformation matrix
rot.at<double>(0,2) += bbox.width/2.0 - center22.x;
rot.at<double>(1,2) += bbox.height/2.0 - center22.y;

Mat dst;
warpAffine(RGBsrc, dst, rot, bbox.size());
imshow("rotated_im", dst);

但我的形象是规模。 主图片: Main image 旋转图像: Rotated and scale image

我该怎么办?

0 个答案:

没有答案