- OpenCV 教程
- OpenCV - 主页
- OpenCV - 概述
- OpenCV - 环境
- OpenCV - 存储图像
- OpenCV - 读取图像
- OpenCV - 写入图像
- OpenCV-图形用户界面
- 绘图功能
- OpenCV - 画一个圆
- OpenCV - 画一条线
- OpenCV - 绘制矩形
- OpenCV - 绘制椭圆
- OpenCV - 绘制折线
- OpenCV - 绘制凸折线
- OpenCV - 绘制箭头线
- OpenCV - 添加文本
- 过滤
- OpenCV - 双边滤波器
- OpenCV - 盒式过滤器
- OpenCV - SQRBox 滤波器
- OpenCV - Filter2D
- OpenCV - 膨胀
- OpenCV - 侵蚀
- OpenCV - 形态运算
- OpenCV - 图像Pyramid
- 摄像头和人脸检测
- OpenCV - 使用相机
- OpenCV - 图片中的人脸检测
- 使用相机进行人脸检测
- OpenCV 有用资源
- OpenCV - 快速指南
- OpenCV - 有用的资源
- OpenCV - 讨论
OpenCV - 旋转
您可以使用imgproc类的warpAffine()方法对图像执行旋转操作。以下是该方法的语法 -
Imgproc.warpAffine(src, dst, rotationMatrix, size);
该方法接受以下参数 -
src -表示此操作的源(输入图像)的Mat对象。
dst -表示此操作的目标(输出图像)的Mat对象。
rotationMatrix -表示旋转矩阵的Mat对象。
size - 表示输出图像大小的整数类型变量。
例子
以下程序演示了如何旋转图像。
import org.opencv.core.Core;
import org.opencv.core.Mat;
import org.opencv.core.Point;
import org.opencv.core.Size;
import org.opencv.imgcodecs.Imgcodecs;
import org.opencv.imgproc.Imgproc;
public class Rotation {
public static void main(String args[]) {
// Loading the OpenCV core library
System.loadLibrary( Core.NATIVE_LIBRARY_NAME );
// Reading the Image from the file and storing it in to a Matrix object
String file ="E:/OpenCV/chap24/transform_input.jpg";
Mat src = Imgcodecs.imread(file);
// Creating an empty matrix to store the result
Mat dst = new Mat();
// Creating a Point object
Point point = new Point(300, 200)
// Creating the transformation matrix M
Mat rotationMatrix = Imgproc.getRotationMatrix2D(point, 30, 1);
// Creating the object of the class Size
Size size = new Size(src.cols(), src.cols());
// Rotating the given image
Imgproc.warpAffine(src, dst, rotationMatrix, size);
// Writing the image
Imgcodecs.imwrite("E:/OpenCV/chap24/rotate_output.jpg", dst);
System.out.println("Image Processed");
}
}
假设以下是上述程序中指定的输入图像transform_input.jpg 。
输出
执行程序时,您将得到以下输出 -
Image Processed
如果打开指定的路径,您可以观察输出图像,如下所示 -
