https://blog.csdn.net/u013105205/article/details/78826789 这篇博客讲的非常清楚(转载自该博客)
对其中最后可展现完整的代码做简单记录(该代码也摘自上边链接的最后一段代码):
Mat img = imread(IMG_PATH);//读入图像
//定义仿射变换的中心、角度、尺度
center=Point2f(img.cols / 2.0, img.rows / 2.0);//原文说要获得完整结果图像,这里变换之前的中心必须为原图的中心
degree=-7;
scale=1;
//获得变换矩阵
rot = getRotationMatrix2D(center, degree, scale);
Mat rimg;
warpAffine(img, rimg, rot, img.size());
// 获取变换之后的 区域,这个很重要,不然的话,变换之后的图像显示不全
Rect bbox;
bbox = RotatedRect(center, Size(scale*img.cols, scale*img.rows), degree).boundingRect();
// 对变换矩阵的最后一列做修改,重新定义变换的 中心
rot.at<double>(0, 2) += bbox.width / 2 - center.x;
rot.at<double>(1, 2) += bbox.height / 2 - center.y;
Mat dst;
warpAffine(img, dst, rot, bbox.size());//此时的dst就是可以显示完整的图像了
imshow("dst", dst);
waitKey(0);
记录内容如有不妥之处,还望指出!