OpenCV-矩阵(图像)旋转-java版

矩阵(图像)旋转

  • 一、Core
    • 1.rotate()
    • 2.rotate()

以下以下图为例进行演示:
在这里插入图片描述

一、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);
    }

结果
OpenCV-矩阵(图像)旋转-java版_第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);
    }

结果:

OpenCV-矩阵(图像)旋转-java版_第2张图片

你可能感兴趣的:(#,OpenCV入门,opencv,矩阵,java)