2011-08-04 14:21:17 +08:00
|
|
|
package org.opencv.test.features2d;
|
|
|
|
|
|
|
|
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-04 14:21:17 +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;
|
2020-04-21 14:58:21 +08:00
|
|
|
import org.opencv.features2d.SIFT;
|
2011-08-04 14:21:17 +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;
|
2022-12-21 21:03:00 +08:00
|
|
|
import org.opencv.features2d.SIFT;
|
2011-08-04 14:21:17 +08:00
|
|
|
|
|
|
|
public class SIFTDescriptorExtractorTest extends OpenCVTestCase {
|
|
|
|
|
2022-12-21 21:03:00 +08:00
|
|
|
SIFT extractor;
|
2011-08-04 14:21:17 +08:00
|
|
|
KeyPoint keypoint;
|
|
|
|
int matSize;
|
2011-08-05 16:39:28 +08:00
|
|
|
Mat truth;
|
2011-08-04 14:21:17 +08:00
|
|
|
|
|
|
|
private Mat getTestImg() {
|
|
|
|
Mat cross = new Mat(matSize, matSize, CvType.CV_8U, new Scalar(255));
|
2014-08-14 17:48:52 +08:00
|
|
|
Imgproc.line(cross, new Point(20, matSize / 2), new Point(matSize - 21, matSize / 2), new Scalar(100), 2);
|
|
|
|
Imgproc.line(cross, new Point(matSize / 2, 20), new Point(matSize / 2, matSize - 21), new Scalar(100), 2);
|
2011-08-04 14:21:17 +08:00
|
|
|
|
|
|
|
return cross;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void setUp() throws Exception {
|
2012-12-28 21:03:35 +08:00
|
|
|
super.setUp();
|
2020-04-21 14:58:21 +08:00
|
|
|
extractor = SIFT.create();
|
2011-08-04 14:21:17 +08:00
|
|
|
keypoint = new KeyPoint(55.775577545166016f, 44.224422454833984f, 16, 9.754629f, 8617.863f, 1, -1);
|
|
|
|
matSize = 100;
|
|
|
|
truth = new Mat(1, 128, CvType.CV_32FC1) {
|
|
|
|
{
|
2012-04-11 03:23:53 +08:00
|
|
|
put(0, 0,
|
2012-10-30 00:34:36 +08:00
|
|
|
0, 0, 0, 1, 3, 0, 0, 0, 15, 23, 22, 20, 24, 2, 0, 0, 7, 8, 2, 0,
|
|
|
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 27, 16, 13, 2, 0, 0, 117,
|
|
|
|
86, 79, 68, 117, 42, 5, 5, 79, 60, 117, 25, 9, 2, 28, 19, 11, 13,
|
|
|
|
20, 2, 0, 0, 5, 8, 0, 0, 76, 58, 34, 31, 97, 16, 95, 49, 117, 92,
|
|
|
|
117, 112, 117, 76, 117, 54, 117, 25, 29, 22, 117, 117, 16, 11, 14,
|
|
|
|
1, 0, 0, 22, 26, 0, 0, 0, 0, 1, 4, 15, 2, 47, 8, 0, 0, 82, 56, 31,
|
|
|
|
17, 81, 12, 0, 0, 26, 23, 18, 23, 0, 0, 0, 0, 0, 0, 0, 0
|
2022-12-21 21:03:00 +08:00
|
|
|
);
|
2011-08-04 14:21:17 +08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2011-08-05 16:39:28 +08:00
|
|
|
public void testComputeListOfMatListOfListOfKeyPointListOfMat() {
|
|
|
|
fail("Not yet implemented");
|
|
|
|
}
|
|
|
|
|
|
|
|
public void testComputeMatListOfKeyPointMat() {
|
2012-04-09 16:20:23 +08:00
|
|
|
MatOfKeyPoint keypoints = new MatOfKeyPoint(keypoint);
|
2011-08-04 14:21:17 +08:00
|
|
|
Mat img = getTestImg();
|
|
|
|
Mat descriptors = new Mat();
|
|
|
|
|
|
|
|
extractor.compute(img, keypoints, descriptors);
|
|
|
|
|
|
|
|
assertMatEqual(truth, descriptors, EPS);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void testCreate() {
|
|
|
|
assertNotNull(extractor);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void testDescriptorSize() {
|
|
|
|
assertEquals(128, extractor.descriptorSize());
|
|
|
|
}
|
|
|
|
|
|
|
|
public void testDescriptorType() {
|
|
|
|
assertEquals(CvType.CV_32F, extractor.descriptorType());
|
|
|
|
}
|
|
|
|
|
|
|
|
public void testEmpty() {
|
2016-10-18 01:53:59 +08:00
|
|
|
// assertFalse(extractor.empty());
|
2022-12-21 21:03:00 +08:00
|
|
|
fail("Not yet implemented"); // SIFT does not override empty() method
|
2011-08-04 14:21:17 +08:00
|
|
|
}
|
|
|
|
|
2022-12-21 21:03:00 +08:00
|
|
|
public void testReadYml() {
|
|
|
|
String filename = OpenCVTestRunner.getTempFileName("yml");
|
|
|
|
writeFile(filename, "%YAML:1.0\n---\nname: \"Feature2D.SIFT\"\nnfeatures: 100\nnOctaveLayers: 4\ncontrastThreshold: 5.0000000000000001e-02\nedgeThreshold: 11\nsigma: 1.7\ndescriptorType: 5\n");
|
2011-08-04 14:21:17 +08:00
|
|
|
|
2022-12-21 21:03:00 +08:00
|
|
|
extractor.read(filename);
|
2011-08-04 14:21:17 +08:00
|
|
|
|
2022-12-21 21:03:00 +08:00
|
|
|
assertEquals(128, extractor.descriptorSize());
|
2011-08-04 14:21:17 +08:00
|
|
|
|
2022-12-21 21:03:00 +08:00
|
|
|
assertEquals(100, extractor.getNFeatures());
|
|
|
|
assertEquals(4, extractor.getNOctaveLayers());
|
|
|
|
assertEquals(0.05, extractor.getContrastThreshold());
|
|
|
|
assertEquals(11., extractor.getEdgeThreshold());
|
|
|
|
assertEquals(1.7, extractor.getSigma());
|
|
|
|
assertEquals(5, extractor.descriptorType());
|
2011-08-04 14:21:17 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
public void testWriteYml() {
|
|
|
|
String filename = OpenCVTestRunner.getTempFileName("yml");
|
|
|
|
|
|
|
|
extractor.write(filename);
|
|
|
|
|
2024-04-10 20:17:15 +08:00
|
|
|
String truth = "%YAML:1.0\n---\nname: \"Feature2D.SIFT\"\nnfeatures: 0\nnOctaveLayers: 3\ncontrastThreshold: 0.040000000000000001\nedgeThreshold: 10.\nsigma: 1.6000000000000001\ndescriptorType: 5\n";
|
2013-01-11 13:13:25 +08:00
|
|
|
String actual = readFile(filename);
|
|
|
|
actual = actual.replaceAll("e([+-])0(\\d\\d)", "e$1$2"); // NOTE: workaround for different platforms double representation
|
|
|
|
assertEquals(truth, actual);
|
2011-08-04 14:21:17 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|