演示 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 −
廣告