Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Tetragramm
GitHub Repository: Tetragramm/opencv
Path: blob/master/samples/java/tutorial_code/features2D/feature_detection/SURFDetectionDemo.java
16354 views
1
import org.opencv.core.Core;
2
import org.opencv.core.Mat;
3
import org.opencv.core.MatOfKeyPoint;
4
import org.opencv.features2d.Features2d;
5
import org.opencv.highgui.HighGui;
6
import org.opencv.imgcodecs.Imgcodecs;
7
import org.opencv.xfeatures2d.SURF;
8
9
class SURFDetection {
10
public void run(String[] args) {
11
String filename = args.length > 0 ? args[0] : "../data/box.png";
12
Mat src = Imgcodecs.imread(filename, Imgcodecs.IMREAD_GRAYSCALE);
13
if (src.empty()) {
14
System.err.println("Cannot read image: " + filename);
15
System.exit(0);
16
}
17
18
//-- Step 1: Detect the keypoints using SURF Detector
19
double hessianThreshold = 400;
20
int nOctaves = 4, nOctaveLayers = 3;
21
boolean extended = false, upright = false;
22
SURF detector = SURF.create(hessianThreshold, nOctaves, nOctaveLayers, extended, upright);
23
MatOfKeyPoint keypoints = new MatOfKeyPoint();
24
detector.detect(src, keypoints);
25
26
//-- Draw keypoints
27
Features2d.drawKeypoints(src, keypoints, src);
28
29
//-- Show detected (drawn) keypoints
30
HighGui.imshow("SURF Keypoints", src);
31
HighGui.waitKey(0);
32
33
System.exit(0);
34
}
35
}
36
37
public class SURFDetectionDemo {
38
public static void main(String[] args) {
39
// Load the native OpenCV library
40
System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
41
42
new SURFDetection().run(args);
43
}
44
}
45
46