opencv中图像旋转—getRotationMatrix2D和warpAffine

API介绍

getRotationMatrix2D:生成旋转矩阵

Mat getRotationMatrix2D(Point2f center, double angle, double scale);

center:旋转的中心点坐标。
angle:顺时针旋转的角度。
scale:图像缩放比例。

warpAffine:仿射变换

void warpAffine(InputArray src, OutputArray dst, InputArray M, Size dsize, int flags = INTER_LINEAR, int borderMode = BORDER_CONSTANT, const Scalar& borderValue = Scalar());

src:原始图像。
dst:输出图像。
M:变换矩阵,这里是由getRotationMatrix2D生成的旋转矩阵。
dsize:输出图像的大小。
flags:插值方法,通常使用INTER_LINEAR。
borderMode:边界像素模式。
borderValue:边界填充值,用于边界外的像素。

示例1

void QuickDemo::rotato_demo(Mat &image) {
   
   
	Mat dst, M;
	int  w = image.cols;
	int h = image.rows;
	M = getRotationMatrix2D(Point2f(w / 2, h / 2), 45, 1.0);//旋转矩阵,围绕图像中心旋转45°
	warpAffine(image, dst, M, image.size(),INTER_LINEAR,0,Scalar(0,0,255));
	
	imshow("旋转45度", dst);
	imwrite("C:/Users/Desktop/opencv-0/warpAffine45.png",dst);
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

算法小菜鸟moon

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值