java opencv 仿射变换旋转图片

	/**
	 * 旋转图片
	 * @param src  原图
	 * @param dst  旋转后图片
	 * @param degree  角度
	 */
	public static void roateImageMat(Mat src, Mat dst, Double degree) {
		Point center = new Point();
		center.x = src.cols() / 2.0;
		center.y = src.rows() / 2.0;
		//旋转90°
		if (degree == 90) {
			 Core.transpose(src, dst);  
			 Core.flip(dst, dst, 1); 
		} else if (degree == -90 || degree == 270) {
			 Core.transpose(src, dst);   
			 Core.flip(dst, dst, 0); 
		} else {
			// 得到旋转矩阵算子
			Mat matrix = Imgproc.getRotationMatrix2D(center, -degree, 1);
			// 旋转
			Imgproc.warpAffine(src, dst, matrix, dst.size(), 1, 0, new Scalar(255, 255, 255));
		}
	}

 对图像应用仿射变换。函数 warpAffine 使用指定的矩阵变换源图像:

        当设置了 WARP_INVERSE_MAP 标志时。 否则,先用 invertAffineTransform 反转变换,然后代入上面的公式,而不是 M。该函数不能就地操作。

 

1.函数 cv::warpAffine (InputArray src, OutputArray dst, InputArray M, Size dsize, int flags=INTER_LINEAR, int borderMode=BORDER_CONSTANT, const Scalar &borderValue=Scalar())
 

2、参数详解
src    输入图像。
dst    输出大小为 dsize 且类型与 src 相同的图像。
M    2×3 变换矩阵。
dsize    输出图像的大小。
flags    插值方法(见 InterpolationFlags)和可选标志 WARP_INVERSE_MAP 的组合,这意味着 M 是逆变换(dst→src)。
borderMode    像素外推法(参见 BorderTypes); 当borderMode=BORDER_TRANSPARENT时,表示目标图像中与源图像中的“异常值”对应的像素未被函数修改。
borderValue    在恒定边界的情况下使用的值; 默认情况下,它是 0。

《伤寒论》
 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

古智云开

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

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

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

打赏作者

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

抵扣说明:

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

余额充值