opencv3_java 图像的旋转Rotate getRotationMatrix2D

图像的旋转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();
			//复制矩阵进入dst
			
			Point 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);
		}

	}

}






你可能感兴趣的:(java,opencv3)