演示 OpenCV 中 Scharr 边缘检测的 Java 示例。
边缘检测领域的Scharr 算子允许你在给定图像的水平和垂直方向上找到边缘。
Imgproc 类中的 Scharr() 方法对给定的图像应用Scharr 边缘检测算法。此方法接受 -
两个代表原图像和目标图像的 Mat 对象。
一个表示图像深度的整型变量。
两个 double 变量用于保存 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[]) {
//Loading the OpenCV core library
System.loadLibrary( Core.NATIVE_LIBRARY_NAME );
String file ="D:\Images\win2.jpg";
Mat src = Imgcodecs.imread(file);
//Creating an empty matrix for the destination image
Mat dst = new Mat();
//Applying Scharr derivative with values x:1 y:0
Imgproc.Scharr(src, dst, Imgproc.CV_SCHARR, 0, 1);
HighGui.imshow("Scharr - x:0 & y:1 ", dst);
//Applying Scharr derivative with values x:1 y:0
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 − 
广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP