The detect() วิธีการของ org.opencv.features2d.Feature2D (นามธรรม) ชั้นตรวจจับจุดสำคัญของภาพที่กำหนด ในวิธีนี้ คุณต้องผ่าน Mat วัตถุที่แสดงภาพต้นฉบับและ MatOfKeyPoint . ที่ว่างเปล่า วัตถุที่จะถืออ่านประเด็นสำคัญ
คุณสามารถวาดจุดสำคัญบนรูปภาพโดยใช้ drawKeypoints() วิธีการของ org.opencv.features2d.Features2d ชั้นเรียน
หมายเหตุ
-
เนื่องจาก Feature2D เป็นคลาสนามธรรม คุณต้องสร้างอินสแตนซ์หนึ่งในคลาสย่อยเพื่อเรียกใช้เมธอด detect() ที่นี่เราใช้คลาส FastFeatureDetector
-
ฟีเจอร์2D และ Features2d เป็นสองคลาสที่แตกต่างกันของแพ็คเกจ features2d อย่าสับสน...
ตัวอย่าง
import org.opencv.core.Core;
import org.opencv.core.Mat;
import org.opencv.core.MatOfKeyPoint;
import org.opencv.core.Scalar;
import org.opencv.features2d.FastFeatureDetector;
import org.opencv.features2d.Features2d;
import org.opencv.highgui.HighGui;z
import org.opencv.imgcodecs.Imgcodecs;
public class DetectingKeyPoints{
public static void main(String args[]) throws Exception {
//Loading the OpenCV core library
System.loadLibrary( Core.NATIVE_LIBRARY_NAME );
//Reading the contents of the image
String file ="D:\\Images\\javafx_graphical.jpg";
Mat src = Imgcodecs.imread(file);
//Reading the key points of the image
Mat dst = new Mat();
MatOfKeyPoint matOfKeyPoints = new MatOfKeyPoint();
FastFeatureDetector featureDetector = FastFeatureDetector.create();
featureDetector.detect(src, matOfKeyPoints);
//Drawing the detected key points
Features2d.drawKeypoints(src, matOfKeyPoints, dst, new Scalar(0, 0, 255));
HighGui.imshow("Feature Detection", dst);
HighGui.waitKey();
}
} ใส่รูปภาพ

ผลลัพธ์
