android opencv 旋转
时间: 2023-07-22 11:19:25 浏览: 140
要在Android OpenCV中旋转图像,可以使用OpenCV中的函数`Imgproc.warpAffine()`。这个函数可以根据指定的旋转角度和旋转中心,对输入图像进行旋转。
以下是一个简单的示例代码,演示如何旋转图像:
```java
Mat src = Imgcodecs.imread("path/to/image.jpg"); // 读取图像
Mat dst = new Mat(); // 新建一个Mat对象,用于存储输出图像
double angle = 45; // 旋转角度
Point center = new Point(src.cols()/2, src.rows()/2); // 旋转中心,这里设为图像中心点
// 计算旋转矩阵
Mat rotationMatrix = Imgproc.getRotationMatrix2D(center, angle, 1);
// 应用旋转矩阵
Imgproc.warpAffine(src, dst, rotationMatrix, src.size());
// 显示输出图像
Imgcodecs.imwrite("path/to/output.jpg", dst);
```
在这个示例代码中,我们首先读取了一个输入图像,并指定了旋转角度和旋转中心。然后,我们使用`Imgproc.getRotationMatrix2D()`函数计算出旋转矩阵。最后,我们使用`Imgproc.warpAffine()`函数将输入图像应用旋转矩阵,得到输出图像。
注意,这里的旋转角度是以度为单位的,而不是弧度。如果要使用弧度,需要将角度值转换为弧度值。
阅读全文
相关推荐















