📜  OpenCV-扩展

📅  最后修改于: 2020-11-23 03:49:37             🧑  作者: Mango


您可以使用imgproc类的resize()方法对图像执行缩放。以下是此方法的语法。

resize(Mat src, Mat dst, Size dsize, double fx, double fy, int interpolation)

此方法接受以下参数-

  • src-一个Mat对象,代表此操作的源(输入图像)。

  • dst-表示此操作的目标(输出图像)的Mat对象。

  • dsize-一个Size对象,代表输出图像的大小。

  • fx-类型为double的变量,代表沿水平轴的比例因子。

  • fy-类型为double的变量,代表沿垂直轴的比例因子。

  • 插值-表示插值方法的整数变量。

以下程序演示了如何将比例转换应用于图像。

import org.opencv.core.Core;
import org.opencv.core.Mat;
import org.opencv.core.Size;

import org.opencv.imgcodecs.Imgcodecs;
import org.opencv.imgproc.Imgproc;

public class Scaling {
   public static void main(String args[]) {
      // Loading the OpenCV core library
      System.loadLibrary( Core.NATIVE_LIBRARY_NAME );

      // Reading the Image from the file and storing it in to a Matrix object
      String file ="E:/OpenCV/chap24/transform_input.jpg";
      Mat src = Imgcodecs.imread(file);

      // Creating an empty matrix to store the result
      Mat dst = new Mat();

      // Creating the Size object
      Size size = new Size(src.rows()*2, src.rows()*2);

      // Scaling the Image
      Imgproc.resize(src, dst, size, 0, 0, Imgproc.INTER_AREA);

      // Writing the image
      Imgcodecs.imwrite("E:/OpenCV/chap24/scale_output.jpg", dst);

      System.out.println("Image Processed");
   }
}

假设下面是上述程序中指定的输入图像transform_input.jpg (大小-宽度:300px和高度:300px)。

转换输入

输出

在执行程序时,您将获得以下输出-

Image Processed

如果打开指定的路径,则可以观察到如下输出图像(大小-宽度:600px和高度:600px)-

规模输出