2011-08-02 22:32:43 +08:00
|
|
|
package org.opencv.test.features2d;
|
|
|
|
|
2012-04-09 16:20:23 +08:00
|
|
|
import java.util.Arrays;
|
|
|
|
|
2011-08-02 22:32:43 +08:00
|
|
|
import org.opencv.core.Core;
|
|
|
|
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-02 22:32:43 +08:00
|
|
|
import org.opencv.core.Point;
|
|
|
|
import org.opencv.core.Scalar;
|
2018-05-14 21:12:29 +08:00
|
|
|
import org.opencv.features2d.Feature2D;
|
|
|
|
import org.opencv.features2d.FastFeatureDetector;
|
2013-03-26 18:58:09 +08:00
|
|
|
import org.opencv.core.KeyPoint;
|
2011-08-02 22:32:43 +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;
|
2011-08-02 22:32:43 +08:00
|
|
|
|
|
|
|
public class FASTFeatureDetectorTest extends OpenCVTestCase {
|
|
|
|
|
2018-05-14 21:12:29 +08:00
|
|
|
Feature2D detector;
|
2011-08-02 22:32:43 +08:00
|
|
|
KeyPoint[] truth;
|
|
|
|
|
2011-08-05 16:39:28 +08:00
|
|
|
private Mat getMaskImg() {
|
|
|
|
Mat mask = new Mat(100, 100, CvType.CV_8U, new Scalar(255));
|
|
|
|
Mat right = mask.submat(0, 100, 50, 100);
|
|
|
|
right.setTo(new Scalar(0));
|
|
|
|
return mask;
|
2011-08-02 22:32:43 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
private Mat getTestImg() {
|
|
|
|
Mat img = new Mat(100, 100, CvType.CV_8U, new Scalar(255));
|
2014-08-14 17:48:52 +08:00
|
|
|
Imgproc.line(img, new Point(30, 30), new Point(70, 70), new Scalar(0), 8);
|
2011-08-02 22:32:43 +08:00
|
|
|
return img;
|
|
|
|
}
|
|
|
|
|
2011-08-05 16:39:28 +08:00
|
|
|
@Override
|
|
|
|
protected void setUp() throws Exception {
|
2012-12-28 21:03:35 +08:00
|
|
|
super.setUp();
|
2018-05-14 21:12:29 +08:00
|
|
|
detector = FastFeatureDetector.create();
|
2011-12-21 20:47:25 +08:00
|
|
|
truth = new KeyPoint[] { new KeyPoint(32, 27, 7, -1, 254, 0, -1), new KeyPoint(27, 32, 7, -1, 254, 0, -1), new KeyPoint(73, 68, 7, -1, 254, 0, -1),
|
|
|
|
new KeyPoint(68, 73, 7, -1, 254, 0, -1) };
|
2011-08-02 22:32:43 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
public void testCreate() {
|
|
|
|
assertNotNull(detector);
|
|
|
|
}
|
|
|
|
|
2011-08-05 16:39:28 +08:00
|
|
|
public void testDetectListOfMatListOfListOfKeyPoint() {
|
|
|
|
fail("Not yet implemented");
|
|
|
|
}
|
2011-08-02 22:32:43 +08:00
|
|
|
|
2011-08-05 16:39:28 +08:00
|
|
|
public void testDetectListOfMatListOfListOfKeyPointListOfMat() {
|
|
|
|
fail("Not yet implemented");
|
2011-08-02 22:32:43 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
public void testDetectMatListOfKeyPoint() {
|
|
|
|
Mat img = getTestImg();
|
2012-04-09 16:20:23 +08:00
|
|
|
MatOfKeyPoint keypoints = new MatOfKeyPoint();
|
2011-08-02 22:32:43 +08:00
|
|
|
|
|
|
|
detector.detect(img, keypoints);
|
|
|
|
|
2012-04-09 16:20:23 +08:00
|
|
|
assertListKeyPointEquals(Arrays.asList(truth), keypoints.toList(), EPS);
|
2011-08-02 22:32:43 +08:00
|
|
|
|
|
|
|
// OpenCVTestRunner.Log("points found: " + keypoints.size());
|
|
|
|
// for (KeyPoint kp : keypoints)
|
|
|
|
// OpenCVTestRunner.Log(kp.toString());
|
|
|
|
}
|
|
|
|
|
2011-08-05 16:39:28 +08:00
|
|
|
public void testDetectMatListOfKeyPointMat() {
|
|
|
|
Mat img = getTestImg();
|
|
|
|
Mat mask = getMaskImg();
|
2012-04-09 16:20:23 +08:00
|
|
|
MatOfKeyPoint keypoints = new MatOfKeyPoint();
|
2011-08-05 16:39:28 +08:00
|
|
|
|
|
|
|
detector.detect(img, keypoints, mask);
|
|
|
|
|
2012-04-09 16:20:23 +08:00
|
|
|
assertListKeyPointEquals(Arrays.asList(truth[0], truth[1]), keypoints.toList(), EPS);
|
2011-08-05 16:39:28 +08:00
|
|
|
}
|
|
|
|
|
2011-08-02 22:32:43 +08:00
|
|
|
public void testEmpty() {
|
2016-10-18 01:53:59 +08:00
|
|
|
// assertFalse(detector.empty());
|
|
|
|
fail("Not yet implemented"); //FAST does not override empty() method
|
2011-08-02 22:32:43 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
public void testRead() {
|
|
|
|
String filename = OpenCVTestRunner.getTempFileName("yml");
|
|
|
|
|
2016-10-19 02:22:18 +08:00
|
|
|
writeFile(filename, "%YAML:1.0\n---\nthreshold: 130\nnonmaxSuppression: 1\n");
|
2011-08-02 22:32:43 +08:00
|
|
|
detector.read(filename);
|
|
|
|
|
2012-04-09 16:20:23 +08:00
|
|
|
MatOfKeyPoint keypoints1 = new MatOfKeyPoint();
|
2011-08-02 22:32:43 +08:00
|
|
|
|
|
|
|
detector.detect(grayChess, keypoints1);
|
|
|
|
|
2016-10-19 02:22:18 +08:00
|
|
|
writeFile(filename, "%YAML:1.0\n---\nthreshold: 150\nnonmaxSuppression: 1\n");
|
2011-08-02 22:32:43 +08:00
|
|
|
detector.read(filename);
|
|
|
|
|
2012-04-09 16:20:23 +08:00
|
|
|
MatOfKeyPoint keypoints2 = new MatOfKeyPoint();
|
2011-08-02 22:32:43 +08:00
|
|
|
|
|
|
|
detector.detect(grayChess, keypoints2);
|
|
|
|
|
2012-04-09 16:20:23 +08:00
|
|
|
assertTrue(keypoints2.total() <= keypoints1.total());
|
2011-08-02 22:32:43 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
public void testReadYml() {
|
|
|
|
String filename = OpenCVTestRunner.getTempFileName("yml");
|
|
|
|
|
2011-08-03 17:27:50 +08:00
|
|
|
writeFile(filename,
|
2011-08-02 22:32:43 +08:00
|
|
|
"<?xml version=\"1.0\"?>\n<opencv_storage>\n<threshold>130</threshold>\n<nonmaxSuppression>1</nonmaxSuppression>\n</opencv_storage>\n");
|
|
|
|
detector.read(filename);
|
|
|
|
|
2012-04-09 16:20:23 +08:00
|
|
|
MatOfKeyPoint keypoints1 = new MatOfKeyPoint();
|
2011-08-02 22:32:43 +08:00
|
|
|
|
|
|
|
detector.detect(grayChess, keypoints1);
|
|
|
|
|
2011-08-03 17:27:50 +08:00
|
|
|
writeFile(filename,
|
2011-08-02 22:32:43 +08:00
|
|
|
"<?xml version=\"1.0\"?>\n<opencv_storage>\n<threshold>150</threshold>\n<nonmaxSuppression>1</nonmaxSuppression>\n</opencv_storage>\n");
|
|
|
|
detector.read(filename);
|
|
|
|
|
2012-04-09 16:20:23 +08:00
|
|
|
MatOfKeyPoint keypoints2 = new MatOfKeyPoint();
|
2011-08-02 22:32:43 +08:00
|
|
|
|
|
|
|
detector.detect(grayChess, keypoints2);
|
|
|
|
|
2012-04-09 16:20:23 +08:00
|
|
|
assertTrue(keypoints2.total() <= keypoints1.total());
|
2011-08-02 22:32:43 +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.FAST</name>\n<nonmaxSuppression>1</nonmaxSuppression>\n<threshold>10</threshold>\n<type>2</type>\n</opencv_storage>\n";
|
|
|
|
String truth = "<?xml version=\"1.0\"?>\n<opencv_storage>\n</opencv_storage>\n";
|
2012-10-30 00:34:36 +08:00
|
|
|
String data = readFile(filename);
|
2013-01-25 21:08:36 +08:00
|
|
|
//Log.d("qqq", "\"" + data + "\"");
|
2012-10-30 00:34:36 +08:00
|
|
|
assertEquals(truth, data);
|
2011-08-02 22:32:43 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
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.FAST\"\nnonmaxSuppression: 1\nthreshold: 10\ntype: 2\n";
|
|
|
|
String truth = "%YAML:1.0\n---\n";
|
2012-10-30 00:34:36 +08:00
|
|
|
String data = readFile(filename);
|
2011-08-02 22:32:43 +08:00
|
|
|
|
2013-01-25 21:08:36 +08:00
|
|
|
//Log.d("qqq", "\"" + data + "\"");
|
2012-10-30 00:34:36 +08:00
|
|
|
assertEquals(truth, data);
|
|
|
|
}
|
2011-08-02 22:32:43 +08:00
|
|
|
}
|