opencv3_java 修改图像大小Resize Imgproc.resize

修改图像大小Resize Imgproc.resize


package opencv_java_demo;

import org.opencv.core.*;
import org.opencv.imgcodecs.*;
import org.opencv.imgproc.*;

public class Resize {

	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
			
			float scale=0.5f;
			float width=src.width();
			float height=src.height();
			
			Imgproc.resize(src, dst, new Size(width*scale,height*scale));
			Imgcodecs.imwrite("./images/resize0.5.jpg",dst);
			
			scale=1.5f;
			Imgproc.resize(src, dst, new Size(width*scale,height*scale));
			Imgcodecs.imwrite("./images/resize1.5.jpg",dst);
			
			Imgproc.resize(src, dst, new Size(400,400));
			Imgcodecs.imwrite("./images/resize400.jpg", dst);
		}catch(Exception e){
			System.out.println("例外:" + e);
		}

	}

}







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