2011-08-03 00:10:58 +08:00
|
|
|
package org.opencv.test.features2d;
|
|
|
|
|
2012-04-09 16:20:23 +08:00
|
|
|
import java.util.Arrays;
|
|
|
|
|
2011-08-03 00:10:58 +08:00
|
|
|
import org.opencv.core.CvType;
|
|
|
|
import org.opencv.core.Mat;
|
2012-04-09 16:20:23 +08:00
|
|
|
import org.opencv.core.MatOfKeyPoint;
|
2011-08-03 00:10:58 +08:00
|
|
|
import org.opencv.core.Point;
|
|
|
|
import org.opencv.core.Scalar;
|
2013-03-26 18:58:09 +08:00
|
|
|
import org.opencv.core.KeyPoint;
|
2011-08-03 00:10:58 +08:00
|
|
|
import org.opencv.test.OpenCVTestCase;
|
|
|
|
import org.opencv.test.OpenCVTestRunner;
|
2014-09-08 21:35:55 +08:00
|
|
|
import org.opencv.imgproc.Imgproc;
|
2016-10-18 01:53:59 +08:00
|
|
|
import org.opencv.features2d.Feature2D;
|
2011-08-03 00:10:58 +08:00
|
|
|
|
|
|
|
public class STARFeatureDetectorTest extends OpenCVTestCase {
|
|
|
|
|
2016-10-18 01:53:59 +08:00
|
|
|
Feature2D detector;
|
2011-08-03 00:10:58 +08:00
|
|
|
int matSize;
|
2011-08-05 16:39:28 +08:00
|
|
|
KeyPoint[] truth;
|
|
|
|
|
|
|
|
private Mat getMaskImg() {
|
|
|
|
Mat mask = new Mat(matSize, matSize, CvType.CV_8U, new Scalar(255));
|
|
|
|
Mat right = mask.submat(0, matSize, matSize / 2, matSize);
|
|
|
|
right.setTo(new Scalar(0));
|
|
|
|
return mask;
|
|
|
|
}
|
|
|
|
|
|
|
|
private Mat getTestImg() {
|
|
|
|
Scalar color = new Scalar(0);
|
|
|
|
int center = matSize / 2;
|
|
|
|
int radius = 6;
|
|
|
|
int offset = 40;
|
|
|
|
|
|
|
|
Mat img = new Mat(matSize, matSize, CvType.CV_8U, new Scalar(255));
|
2014-09-08 21:35:55 +08:00
|
|
|
Imgproc.circle(img, new Point(center - offset, center), radius, color, -1);
|
|
|
|
Imgproc.circle(img, new Point(center + offset, center), radius, color, -1);
|
|
|
|
Imgproc.circle(img, new Point(center, center - offset), radius, color, -1);
|
|
|
|
Imgproc.circle(img, new Point(center, center + offset), radius, color, -1);
|
|
|
|
Imgproc.circle(img, new Point(center, center), radius, color, -1);
|
2011-08-05 16:39:28 +08:00
|
|
|
return img;
|
|
|
|
}
|
2011-08-03 00:10:58 +08:00
|
|
|
|
|
|
|
protected void setUp() throws Exception {
|
2012-12-28 21:03:35 +08:00
|
|
|
super.setUp();
|
2016-10-19 02:22:18 +08:00
|
|
|
detector = createClassInstance(XFEATURES2D+"StarDetector", DEFAULT_FACTORY, null, null);
|
2011-08-03 00:10:58 +08:00
|
|
|
matSize = 200;
|
|
|
|
truth = new KeyPoint[] {
|
2012-10-17 07:18:30 +08:00
|
|
|
new KeyPoint( 95, 80, 22, -1, 31.5957f, 0, -1),
|
|
|
|
new KeyPoint(105, 80, 22, -1, 31.5957f, 0, -1),
|
|
|
|
new KeyPoint( 80, 95, 22, -1, 31.5957f, 0, -1),
|
|
|
|
new KeyPoint(120, 95, 22, -1, 31.5957f, 0, -1),
|
|
|
|
new KeyPoint(100, 100, 8, -1, 30.f, 0, -1),
|
|
|
|
new KeyPoint( 80, 105, 22, -1, 31.5957f, 0, -1),
|
|
|
|
new KeyPoint(120, 105, 22, -1, 31.5957f, 0, -1),
|
|
|
|
new KeyPoint( 95, 120, 22, -1, 31.5957f, 0, -1),
|
|
|
|
new KeyPoint(105, 120, 22, -1, 31.5957f, 0, -1)
|
2012-04-10 23:01:10 +08:00
|
|
|
};
|
2011-08-03 00:10:58 +08:00
|
|
|
}
|
|
|
|
|
2011-08-05 16:39:28 +08:00
|
|
|
public void testCreate() {
|
|
|
|
assertNotNull(detector);
|
2011-08-03 00:10:58 +08:00
|
|
|
}
|
|
|
|
|
2011-08-05 16:39:28 +08:00
|
|
|
public void testDetectListOfMatListOfListOfKeyPoint() {
|
|
|
|
fail("Not yet implemented");
|
2011-08-03 00:10:58 +08:00
|
|
|
}
|
|
|
|
|
2011-08-05 16:39:28 +08:00
|
|
|
public void testDetectListOfMatListOfListOfKeyPointListOfMat() {
|
|
|
|
fail("Not yet implemented");
|
2011-08-03 00:10:58 +08:00
|
|
|
}
|
|
|
|
|
2011-08-05 16:39:28 +08:00
|
|
|
public void testDetectMatListOfKeyPoint() {
|
2011-08-03 00:10:58 +08:00
|
|
|
Mat img = getTestImg();
|
2012-04-09 16:20:23 +08:00
|
|
|
MatOfKeyPoint keypoints = new MatOfKeyPoint();
|
2011-08-03 00:10:58 +08:00
|
|
|
|
2011-08-05 16:39:28 +08:00
|
|
|
detector.detect(img, keypoints);
|
2011-08-03 00:10:58 +08:00
|
|
|
|
2012-04-09 16:20:23 +08:00
|
|
|
assertListKeyPointEquals(Arrays.asList(truth), keypoints.toList(), EPS);
|
2011-08-03 00:10:58 +08:00
|
|
|
}
|
|
|
|
|
2011-08-05 16:39:28 +08:00
|
|
|
public void testDetectMatListOfKeyPointMat() {
|
2011-08-03 00:10:58 +08:00
|
|
|
Mat img = getTestImg();
|
2011-08-05 16:39:28 +08:00
|
|
|
Mat mask = getMaskImg();
|
2012-04-09 16:20:23 +08:00
|
|
|
MatOfKeyPoint keypoints = new MatOfKeyPoint();
|
2011-08-03 00:10:58 +08:00
|
|
|
|
2011-08-05 16:39:28 +08:00
|
|
|
detector.detect(img, keypoints, mask);
|
2011-08-03 00:10:58 +08:00
|
|
|
|
2012-04-09 16:20:23 +08:00
|
|
|
assertListKeyPointEquals(Arrays.asList(truth[0], truth[2], truth[5], truth[7]), keypoints.toList(), EPS);
|
2011-08-03 00:10:58 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
public void testEmpty() {
|
2016-10-18 01:53:59 +08:00
|
|
|
// assertFalse(detector.empty());
|
|
|
|
fail("Not yet implemented");
|
2011-08-03 00:10:58 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
public void testRead() {
|
|
|
|
Mat img = getTestImg();
|
2011-08-05 16:39:28 +08:00
|
|
|
|
2012-04-09 16:20:23 +08:00
|
|
|
MatOfKeyPoint keypoints1 = new MatOfKeyPoint();
|
2011-08-03 00:10:58 +08:00
|
|
|
detector.detect(img, keypoints1);
|
2011-08-05 16:39:28 +08:00
|
|
|
|
2011-08-03 00:10:58 +08:00
|
|
|
String filename = OpenCVTestRunner.getTempFileName("yml");
|
2016-10-19 02:22:18 +08:00
|
|
|
writeFile(filename, "%YAML:1.0\n---\nmaxSize: 45\nresponseThreshold: 150\nlineThresholdProjected: 10\nlineThresholdBinarized: 8\nsuppressNonmaxSize: 5\n");
|
2011-08-03 00:10:58 +08:00
|
|
|
detector.read(filename);
|
2011-08-05 16:39:28 +08:00
|
|
|
|
2012-04-09 16:20:23 +08:00
|
|
|
MatOfKeyPoint keypoints2 = new MatOfKeyPoint();
|
2011-08-03 00:10:58 +08:00
|
|
|
detector.detect(img, keypoints2);
|
2011-08-05 16:39:28 +08:00
|
|
|
|
2012-04-09 16:20:23 +08:00
|
|
|
assertTrue(keypoints2.total() <= keypoints1.total());
|
2011-08-03 00:10:58 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
public void testWrite() {
|
|
|
|
String filename = OpenCVTestRunner.getTempFileName("xml");
|
|
|
|
|
|
|
|
detector.write(filename);
|
|
|
|
|
2016-10-18 01:53:59 +08:00
|
|
|
// 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";
|
|
|
|
String truth = "<?xml version=\"1.0\"?>\n<opencv_storage>\n</opencv_storage>\n";
|
2011-08-03 00:10:58 +08:00
|
|
|
assertEquals(truth, readFile(filename));
|
|
|
|
}
|
|
|
|
|
|
|
|
public void testWriteYml() {
|
|
|
|
String filename = OpenCVTestRunner.getTempFileName("yml");
|
|
|
|
|
|
|
|
detector.write(filename);
|
|
|
|
|
2016-10-19 02:22:18 +08:00
|
|
|
// String truth = "%YAML:1.0\n---\nname: \"Feature2D.STAR\"\nlineThresholdBinarized: 8\nlineThresholdProjected: 10\nmaxSize: 45\nresponseThreshold: 30\nsuppressNonmaxSize: 5\n";
|
|
|
|
String truth = "%YAML:1.0\n---\n";
|
2011-08-03 00:10:58 +08:00
|
|
|
assertEquals(truth, readFile(filename));
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|