要对一副图像进行旋转,并且旋转后的图像的宽度和高度自己设置。这本来是一个很简单的问题,但是看了网上很多人的做法,搞得非常的复杂,完全没有必要。下面附上最简单的代码,至于原理,学过图像处理都应该知道了。
// 计算绕图像中点顺时针旋转50度缩放因子为1的旋转矩阵
Mat ImageIn = imread("E:/auto_focus/cache_bmp1/roate/080_c.tif", -1);
Point center = Point( ImageIn.cols/2, ImageIn.rows/2 );
double angle = -50.0;
double scale = 1;
// 通过上面的旋转细节信息求得旋转矩阵
Mat rot_mat = getRotationMatrix2D( center, angle, scale );
Mat result;
// 旋转已扭曲图像
warpAffine( ImageIn, result, rot_mat, ImageIn.size() );
//保存
imwrite("Result.tif", result);