mirror of https://github.com/opencv/opencv.git
Open Source Computer Vision Library
https://opencv.org/
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
147 lines
4.6 KiB
147 lines
4.6 KiB
14 years ago
|
package org.opencv.test.features2d;
|
||
|
|
||
13 years ago
|
import java.util.Arrays;
|
||
|
|
||
14 years ago
|
import org.opencv.core.Core;
|
||
|
import org.opencv.core.CvType;
|
||
|
import org.opencv.core.Mat;
|
||
13 years ago
|
import org.opencv.core.MatOfKeyPoint;
|
||
14 years ago
|
import org.opencv.core.Point;
|
||
|
import org.opencv.core.Scalar;
|
||
|
import org.opencv.features2d.FeatureDetector;
|
||
12 years ago
|
import org.opencv.core.KeyPoint;
|
||
14 years ago
|
import org.opencv.test.OpenCVTestCase;
|
||
|
import org.opencv.test.OpenCVTestRunner;
|
||
10 years ago
|
import org.opencv.imgproc.Imgproc;
|
||
14 years ago
|
|
||
|
public class FASTFeatureDetectorTest extends OpenCVTestCase {
|
||
|
|
||
|
FeatureDetector detector;
|
||
|
KeyPoint[] truth;
|
||
|
|
||
14 years ago
|
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;
|
||
14 years ago
|
}
|
||
|
|
||
|
private Mat getTestImg() {
|
||
|
Mat img = new Mat(100, 100, CvType.CV_8U, new Scalar(255));
|
||
10 years ago
|
Imgproc.line(img, new Point(30, 30), new Point(70, 70), new Scalar(0), 8);
|
||
14 years ago
|
return img;
|
||
|
}
|
||
|
|
||
14 years ago
|
@Override
|
||
|
protected void setUp() throws Exception {
|
||
12 years ago
|
super.setUp();
|
||
14 years ago
|
detector = FeatureDetector.create(FeatureDetector.FAST);
|
||
13 years ago
|
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) };
|
||
14 years ago
|
}
|
||
|
|
||
|
public void testCreate() {
|
||
|
assertNotNull(detector);
|
||
|
}
|
||
|
|
||
14 years ago
|
public void testDetectListOfMatListOfListOfKeyPoint() {
|
||
|
fail("Not yet implemented");
|
||
|
}
|
||
14 years ago
|
|
||
14 years ago
|
public void testDetectListOfMatListOfListOfKeyPointListOfMat() {
|
||
|
fail("Not yet implemented");
|
||
14 years ago
|
}
|
||
|
|
||
|
public void testDetectMatListOfKeyPoint() {
|
||
|
Mat img = getTestImg();
|
||
13 years ago
|
MatOfKeyPoint keypoints = new MatOfKeyPoint();
|
||
14 years ago
|
|
||
|
detector.detect(img, keypoints);
|
||
|
|
||
13 years ago
|
assertListKeyPointEquals(Arrays.asList(truth), keypoints.toList(), EPS);
|
||
14 years ago
|
|
||
|
// OpenCVTestRunner.Log("points found: " + keypoints.size());
|
||
|
// for (KeyPoint kp : keypoints)
|
||
|
// OpenCVTestRunner.Log(kp.toString());
|
||
|
}
|
||
|
|
||
14 years ago
|
public void testDetectMatListOfKeyPointMat() {
|
||
|
Mat img = getTestImg();
|
||
|
Mat mask = getMaskImg();
|
||
13 years ago
|
MatOfKeyPoint keypoints = new MatOfKeyPoint();
|
||
14 years ago
|
|
||
|
detector.detect(img, keypoints, mask);
|
||
|
|
||
13 years ago
|
assertListKeyPointEquals(Arrays.asList(truth[0], truth[1]), keypoints.toList(), EPS);
|
||
14 years ago
|
}
|
||
|
|
||
14 years ago
|
public void testEmpty() {
|
||
|
assertFalse(detector.empty());
|
||
|
}
|
||
|
|
||
|
public void testRead() {
|
||
|
String filename = OpenCVTestRunner.getTempFileName("yml");
|
||
|
|
||
|
writeFile(filename, "%YAML:1.0\nthreshold: 130\nnonmaxSuppression: 1\n");
|
||
|
detector.read(filename);
|
||
|
|
||
13 years ago
|
MatOfKeyPoint keypoints1 = new MatOfKeyPoint();
|
||
14 years ago
|
|
||
|
detector.detect(grayChess, keypoints1);
|
||
|
|
||
|
writeFile(filename, "%YAML:1.0\nthreshold: 150\nnonmaxSuppression: 1\n");
|
||
|
detector.read(filename);
|
||
|
|
||
13 years ago
|
MatOfKeyPoint keypoints2 = new MatOfKeyPoint();
|
||
14 years ago
|
|
||
|
detector.detect(grayChess, keypoints2);
|
||
|
|
||
13 years ago
|
assertTrue(keypoints2.total() <= keypoints1.total());
|
||
14 years ago
|
}
|
||
|
|
||
|
public void testReadYml() {
|
||
|
String filename = OpenCVTestRunner.getTempFileName("yml");
|
||
|
|
||
14 years ago
|
writeFile(filename,
|
||
14 years ago
|
"<?xml version=\"1.0\"?>\n<opencv_storage>\n<threshold>130</threshold>\n<nonmaxSuppression>1</nonmaxSuppression>\n</opencv_storage>\n");
|
||
|
detector.read(filename);
|
||
|
|
||
13 years ago
|
MatOfKeyPoint keypoints1 = new MatOfKeyPoint();
|
||
14 years ago
|
|
||
|
detector.detect(grayChess, keypoints1);
|
||
|
|
||
14 years ago
|
writeFile(filename,
|
||
14 years ago
|
"<?xml version=\"1.0\"?>\n<opencv_storage>\n<threshold>150</threshold>\n<nonmaxSuppression>1</nonmaxSuppression>\n</opencv_storage>\n");
|
||
|
detector.read(filename);
|
||
|
|
||
13 years ago
|
MatOfKeyPoint keypoints2 = new MatOfKeyPoint();
|
||
14 years ago
|
|
||
|
detector.detect(grayChess, keypoints2);
|
||
|
|
||
13 years ago
|
assertTrue(keypoints2.total() <= keypoints1.total());
|
||
14 years ago
|
}
|
||
|
|
||
|
public void testWrite() {
|
||
|
String filename = OpenCVTestRunner.getTempFileName("xml");
|
||
|
|
||
|
detector.write(filename);
|
||
|
|
||
12 years ago
|
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";
|
||
12 years ago
|
String data = readFile(filename);
|
||
12 years ago
|
//Log.d("qqq", "\"" + data + "\"");
|
||
12 years ago
|
assertEquals(truth, data);
|
||
14 years ago
|
}
|
||
|
|
||
|
public void testWriteYml() {
|
||
|
String filename = OpenCVTestRunner.getTempFileName("yml");
|
||
|
|
||
|
detector.write(filename);
|
||
|
|
||
12 years ago
|
String truth = "%YAML:1.0\nname: \"Feature2D.FAST\"\nnonmaxSuppression: 1\nthreshold: 10\ntype: 2\n";
|
||
12 years ago
|
String data = readFile(filename);
|
||
14 years ago
|
|
||
12 years ago
|
//Log.d("qqq", "\"" + data + "\"");
|
||
12 years ago
|
assertEquals(truth, data);
|
||
|
}
|
||
14 years ago
|
}
|