ตัวดำเนินการ Sobel สำหรับการตรวจจับขอบช่วยให้คุณค้นหาขอบในภาพที่กำหนดทั้งในแนวนอนและแนวตั้ง
Sobel() เมธอดของคลาส Imgproc ใช้อัลกอริทึม Sobel Edge Detection กับรูปภาพที่กำหนด วิธีนี้ยอมรับ -
-
วัตถุ 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 SobelEdgeDetection {
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 sobel derivative with values x:0 y:1
Imgproc.Sobel(src, dst, -1, 0, 1);
HighGui.imshow("Sobel - x:0 & y:1 ", dst);
HighGui.waitKey();
//Applying sobel derivative with values x:1 y:0
Imgproc.Sobel(src, dst, -1, 1, 0);
HighGui.imshow("Sobel - x:1 & y:0 ", dst);
HighGui.waitKey();
//Applying sobel derivative with values x:1 y:1
Imgproc.Sobel(src, dst, -1, 1, 1);
HighGui.imshow("Sobel - x:1 & y:1 ", dst);
HighGui.waitKey();
}
} ผลลัพธ์
ในการดำเนินการ โปรแกรมดังกล่าวจะสร้างหน้าต่างต่อไปนี้ -
Sobel - x:0 &y:1 −

Sobel - x:1 &y:0 −

Sobel - x:1 &y:1 −
