我通过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);
我该怎么办?