opencv3_java 图像的旋转Rotate getRotationMatrix2D

来源:互联网 发布:mac电脑装windows10 编辑:程序博客网 时间:2024/05/04 09:25

图像的旋转Rotate getRotationMatrix2D


package opencv_java_demo;import org.opencv.core.*;import org.opencv.imgcodecs.*;import org.opencv.imgproc.*;public class Rotate {public static void main(String[] args) {try{System.loadLibrary(Core.NATIVE_LIBRARY_NAME);Mat src=Imgcodecs.imread("./images/lenna.jpg");//读取图像到矩阵中if(src.empty()){throw new Exception("no file");}Mat dst=src.clone();//复制矩阵进入dstPoint center =new Point(src.width()/2.0,src.height()/2.0);Mat affineTrans=Imgproc.getRotationMatrix2D(center, 33.0, 1.0);Imgproc.warpAffine(src, dst, affineTrans, dst.size(),Imgproc.INTER_NEAREST);Imgcodecs.imwrite("./images/rotate_033.jpg",dst);affineTrans=Imgproc.getRotationMatrix2D(center, 110.0, 1.1);Imgproc.warpAffine(src,dst,affineTrans,dst.size(),Imgproc.INTER_NEAREST);Imgcodecs.imwrite("./images/rotate_110.jpg",dst);}catch(Exception e){System.out.println("例外:" + e);}}}