矩阵(图像)旋转
以下以下图为例进行演示:
一、Core
openCV的core包中提供了flip()函数和rotate()函数对矩阵进行旋转
1.rotate()
方法 | 说明 |
flip(Mat src, Mat dst, int flipCode) | src:原图像 dst:目标图像 flipCode:旋转方向对应的值(0 垂直, <0 水平+垂直 , >0水平 |
public static void main(String[] args) {
String libraryPath= System.getProperty("user.dir")+"\\lib\\opencv_java460.dll";
System.load(libraryPath);
Mat img = Imgcodecs.imread("rabbit.jpg");
Mat mat = new Mat();
//垂直旋转
Core.flip(img,mat,0);
HighGui.imshow("mat",mat);
HighGui.waitKey(1);
}
结果
2.rotate()
方法 | 说明 |
rotate(Mat src, Mat dst, int rotateCode) | src:原图像 dst:目标图像 rotateCode:旋转方向对应的值(0 顺时针90度,1 顺时针180度, 2 顺时针 270度) |
public static void main(String[] args) {
String libraryPath= System.getProperty("user.dir")+"\\lib\\opencv_java460.dll";
System.load(libraryPath);
Mat img = Imgcodecs.imread("rabbit.jpg");
Mat mat = new Mat();
//顺时针旋转180度
Core.rotate(img,mat, 1);
HighGui.imshow("mat",mat);
HighGui.waitKey(1);
}
结果: