Java 示例演示 OpenCV 中的 Scharr 边缘检测。

javaobject oriented programmingprogramming更新于 2025/10/9 13:00:17

用于边缘检测的 Scharr 运算符允许您在水平和垂直方向上查找给定图像中的边缘。

Imgproc 类的 Scharr() 方法将 Scharr  边缘检测算法应用于给定图像。此方法接受 −

  • 两个 Mat 对象,分别表示源图像和目标图像。

  • 一个表示图像深度的整数变量。

  • 两个双精度变量,用于保存 x 和 y 导数。

示例

import org.opencv.core.Core;
import org.opencv.core.Mat;
import org.opencv.highgui.HighGui;
import org.opencv.imgcodecs.Imgcodecs;
import org.opencv.imgproc.Imgproc;
public class ScharrEdgeDetection {
   public static void main(String args[]) {
      //加载 OpenCV 核心库
      System.loadLibrary( Core.NATIVE_LIBRARY_NAME );
      String file ="D:\Images\win2.jpg";
      Mat src = Imgcodecs.imread(file);
      //为目标图像创建一个空矩阵
      Mat dst = new Mat();
      //应用值为 x:1 y:0 的 Scharr 导数
      Imgproc.Scharr(src, dst, Imgproc.CV_SCHARR, 0, 1);
      HighGui.imshow("Scharr - x:0 & y:1 ", dst);
      //应用值为 x:1 y:0 的 Scharr 导数
      Imgproc.Scharr(src, dst, Imgproc.CV_SCHARR, 1, 0);
      HighGui.imshow("Scharr - x:1 & y:0 ", dst);
      HighGui.waitKey();
   }
}

输入图片

输出

执行时,上述程序生成以下窗口 −

Scharr - x:0 & y:1 − 

Scharr - x:1 & y:0 − 


相关文章


有用资源