1 package org.opencv.test.features2d;
3 import java.util.Arrays;
5 import org.opencv.core.CvType;
6 import org.opencv.core.Mat;
7 import org.opencv.core.MatOfKeyPoint;
8 import org.opencv.core.Point;
9 import org.opencv.core.Scalar;
10 import org.opencv.core.KeyPoint;
11 import org.opencv.test.OpenCVTestCase;
12 import org.opencv.test.OpenCVTestRunner;
13 import org.opencv.imgproc.Imgproc;
14 import org.opencv.features2d.Feature2D;
16 public class STARFeatureDetectorTest extends OpenCVTestCase {
22 private Mat getMaskImg() {
23 Mat mask = new Mat(matSize, matSize, CvType.CV_8U, new Scalar(255));
24 Mat right = mask.submat(0, matSize, matSize / 2, matSize);
25 right.setTo(new Scalar(0));
29 private Mat getTestImg() {
30 Scalar color = new Scalar(0);
31 int center = matSize / 2;
35 Mat img = new Mat(matSize, matSize, CvType.CV_8U, new Scalar(255));
36 Imgproc.circle(img, new Point(center - offset, center), radius, color, -1);
37 Imgproc.circle(img, new Point(center + offset, center), radius, color, -1);
38 Imgproc.circle(img, new Point(center, center - offset), radius, color, -1);
39 Imgproc.circle(img, new Point(center, center + offset), radius, color, -1);
40 Imgproc.circle(img, new Point(center, center), radius, color, -1);
44 protected void setUp() throws Exception {
46 detector = createClassInstance(XFEATURES2D+"StarDetector", DEFAULT_FACTORY, null, null);
48 truth = new KeyPoint[] {
49 new KeyPoint( 95, 80, 22, -1, 31.5957f, 0, -1),
50 new KeyPoint(105, 80, 22, -1, 31.5957f, 0, -1),
51 new KeyPoint( 80, 95, 22, -1, 31.5957f, 0, -1),
52 new KeyPoint(120, 95, 22, -1, 31.5957f, 0, -1),
53 new KeyPoint(100, 100, 8, -1, 30.f, 0, -1),
54 new KeyPoint( 80, 105, 22, -1, 31.5957f, 0, -1),
55 new KeyPoint(120, 105, 22, -1, 31.5957f, 0, -1),
56 new KeyPoint( 95, 120, 22, -1, 31.5957f, 0, -1),
57 new KeyPoint(105, 120, 22, -1, 31.5957f, 0, -1)
61 public void testCreate() {
62 assertNotNull(detector);
65 public void testDetectListOfMatListOfListOfKeyPoint() {
66 fail("Not yet implemented");
69 public void testDetectListOfMatListOfListOfKeyPointListOfMat() {
70 fail("Not yet implemented");
73 public void testDetectMatListOfKeyPoint() {
74 Mat img = getTestImg();
75 MatOfKeyPoint keypoints = new MatOfKeyPoint();
77 detector.detect(img, keypoints);
79 assertListKeyPointEquals(Arrays.asList(truth), keypoints.toList(), EPS);
82 public void testDetectMatListOfKeyPointMat() {
83 Mat img = getTestImg();
84 Mat mask = getMaskImg();
85 MatOfKeyPoint keypoints = new MatOfKeyPoint();
87 detector.detect(img, keypoints, mask);
89 assertListKeyPointEquals(Arrays.asList(truth[0], truth[2], truth[5], truth[7]), keypoints.toList(), EPS);
92 public void testEmpty() {
93 // assertFalse(detector.empty());
94 fail("Not yet implemented");
97 public void testRead() {
98 Mat img = getTestImg();
100 MatOfKeyPoint keypoints1 = new MatOfKeyPoint();
101 detector.detect(img, keypoints1);
103 String filename = OpenCVTestRunner.getTempFileName("yml");
104 writeFile(filename, "%YAML:1.0\n---\nmaxSize: 45\nresponseThreshold: 150\nlineThresholdProjected: 10\nlineThresholdBinarized: 8\nsuppressNonmaxSize: 5\n");
105 detector.read(filename);
107 MatOfKeyPoint keypoints2 = new MatOfKeyPoint();
108 detector.detect(img, keypoints2);
110 assertTrue(keypoints2.total() <= keypoints1.total());
113 public void testWrite() {
114 String filename = OpenCVTestRunner.getTempFileName("xml");
116 detector.write(filename);
118 // String truth = "<?xml version=\"1.0\"?>\n<opencv_storage>\n<name>Feature2D.STAR</name>\n<lineThresholdBinarized>8</lineThresholdBinarized>\n<lineThresholdProjected>10</lineThresholdProjected>\n<maxSize>45</maxSize>\n<responseThreshold>30</responseThreshold>\n<suppressNonmaxSize>5</suppressNonmaxSize>\n</opencv_storage>\n";
119 String truth = "<?xml version=\"1.0\"?>\n<opencv_storage>\n</opencv_storage>\n";
120 assertEquals(truth, readFile(filename));
123 public void testWriteYml() {
124 String filename = OpenCVTestRunner.getTempFileName("yml");
126 detector.write(filename);
128 // String truth = "%YAML:1.0\n---\nname: \"Feature2D.STAR\"\nlineThresholdBinarized: 8\nlineThresholdProjected: 10\nmaxSize: 45\nresponseThreshold: 30\nsuppressNonmaxSize: 5\n";
129 String truth = "%YAML:1.0\n---\n";
130 assertEquals(truth, readFile(filename));