Merge pull request #20367 from augustinmanecy:features2d-rw
**Merge with contrib**: https://github.com/opencv/opencv_contrib/pull/3003 ### Pull Request Readiness Checklist See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request - [x] I agree to contribute to the project under Apache 2 License. - [x] To the best of my knowledge, the proposed patch is not based on a code under GPL or other license that is incompatible with OpenCV - [x] The PR is proposed to proper branch - [ ] There is reference to original bug report and related work - [x] There is accuracy test, performance test and test data in opencv_extra repository, if applicable Patch to opencv_extra has the same branch name. - [ ] The feature is well documented and sample code can be built with the project CMakepull/23012/head
parent
63b6b24cd0
commit
0bd54a60e9
28 changed files with 845 additions and 555 deletions
@ -0,0 +1,85 @@ |
||||
package org.opencv.test.features2d; |
||||
|
||||
import org.opencv.test.OpenCVTestCase; |
||||
import org.opencv.test.OpenCVTestRunner; |
||||
import org.opencv.features2d.AgastFeatureDetector; |
||||
|
||||
public class AGASTFeatureDetectorTest extends OpenCVTestCase { |
||||
|
||||
AgastFeatureDetector detector; |
||||
|
||||
@Override |
||||
protected void setUp() throws Exception { |
||||
super.setUp(); |
||||
detector = AgastFeatureDetector.create(); // default (10,true,3)
|
||||
} |
||||
|
||||
public void testCreate() { |
||||
assertNotNull(detector); |
||||
} |
||||
|
||||
public void testDetectListOfMatListOfListOfKeyPoint() { |
||||
fail("Not yet implemented"); |
||||
} |
||||
|
||||
public void testDetectListOfMatListOfListOfKeyPointListOfMat() { |
||||
fail("Not yet implemented"); |
||||
} |
||||
|
||||
public void testDetectMatListOfKeyPoint() { |
||||
fail("Not yet implemented"); |
||||
} |
||||
|
||||
public void testDetectMatListOfKeyPointMat() { |
||||
fail("Not yet implemented"); |
||||
} |
||||
|
||||
public void testEmpty() { |
||||
fail("Not yet implemented"); |
||||
} |
||||
|
||||
public void testRead() { |
||||
String filename = OpenCVTestRunner.getTempFileName("xml"); |
||||
writeFile(filename, "<?xml version=\"1.0\"?>\n<opencv_storage>\n<name>Feature2D.AgastFeatureDetector</name>\n<threshold>11</threshold>\n<nonmaxSuppression>0</nonmaxSuppression>\n<type>2</type>\n</opencv_storage>\n"); |
||||
|
||||
detector.read(filename); |
||||
|
||||
assertEquals(11, detector.getThreshold()); |
||||
assertEquals(false, detector.getNonmaxSuppression()); |
||||
assertEquals(2, detector.getType()); |
||||
} |
||||
|
||||
public void testReadYml() { |
||||
String filename = OpenCVTestRunner.getTempFileName("yml"); |
||||
writeFile(filename, "%YAML:1.0\n---\nname: \"Feature2D.AgastFeatureDetector\"\nthreshold: 11\nnonmaxSuppression: 0\ntype: 2\n"); |
||||
|
||||
detector.read(filename); |
||||
|
||||
assertEquals(11, detector.getThreshold()); |
||||
assertEquals(false, detector.getNonmaxSuppression()); |
||||
assertEquals(2, detector.getType()); |
||||
} |
||||
|
||||
public void testWrite() { |
||||
String filename = OpenCVTestRunner.getTempFileName("xml"); |
||||
|
||||
detector.write(filename); |
||||
|
||||
String truth = "<?xml version=\"1.0\"?>\n<opencv_storage>\n<name>Feature2D.AgastFeatureDetector</name>\n<threshold>10</threshold>\n<nonmaxSuppression>1</nonmaxSuppression>\n<type>3</type>\n</opencv_storage>\n"; |
||||
String actual = readFile(filename); |
||||
actual = actual.replaceAll("e([+-])0(\\d\\d)", "e$1$2"); // NOTE: workaround for different platforms double representation
|
||||
assertEquals(truth, actual); |
||||
} |
||||
|
||||
public void testWriteYml() { |
||||
String filename = OpenCVTestRunner.getTempFileName("yml"); |
||||
|
||||
detector.write(filename); |
||||
|
||||
String truth = "%YAML:1.0\n---\nname: \"Feature2D.AgastFeatureDetector\"\nthreshold: 10\nnonmaxSuppression: 1\ntype: 3\n"; |
||||
String actual = readFile(filename); |
||||
actual = actual.replaceAll("e([+-])0(\\d\\d)", "e$1$2"); // NOTE: workaround for different platforms double representation
|
||||
assertEquals(truth, actual); |
||||
} |
||||
|
||||
} |
@ -0,0 +1,67 @@ |
||||
package org.opencv.test.features2d; |
||||
|
||||
import org.opencv.test.OpenCVTestCase; |
||||
import org.opencv.test.OpenCVTestRunner; |
||||
import org.opencv.features2d.AKAZE; |
||||
|
||||
public class AKAZEDescriptorExtractorTest extends OpenCVTestCase { |
||||
|
||||
AKAZE extractor; |
||||
|
||||
@Override |
||||
protected void setUp() throws Exception { |
||||
super.setUp(); |
||||
extractor = AKAZE.create(); // default (5,0,3,0.001f,4,4,1)
|
||||
} |
||||
|
||||
public void testCreate() { |
||||
assertNotNull(extractor); |
||||
} |
||||
|
||||
public void testDetectListOfMatListOfListOfKeyPoint() { |
||||
fail("Not yet implemented"); |
||||
} |
||||
|
||||
public void testDetectListOfMatListOfListOfKeyPointListOfMat() { |
||||
fail("Not yet implemented"); |
||||
} |
||||
|
||||
public void testDetectMatListOfKeyPoint() { |
||||
fail("Not yet implemented"); |
||||
} |
||||
|
||||
public void testDetectMatListOfKeyPointMat() { |
||||
fail("Not yet implemented"); |
||||
} |
||||
|
||||
public void testEmpty() { |
||||
fail("Not yet implemented"); |
||||
} |
||||
|
||||
public void testReadYml() { |
||||
String filename = OpenCVTestRunner.getTempFileName("yml"); |
||||
writeFile(filename, "%YAML:1.0\n---\nformat: 3\nname: \"Feature2D.AKAZE\"\ndescriptor: 4\ndescriptor_channels: 2\ndescriptor_size: 32\nthreshold: 0.125\noctaves: 3\nsublevels: 5\ndiffusivity: 2\n"); |
||||
|
||||
extractor.read(filename); |
||||
|
||||
assertEquals(4, extractor.getDescriptorType()); |
||||
assertEquals(2, extractor.getDescriptorChannels()); |
||||
assertEquals(32, extractor.getDescriptorSize()); |
||||
assertEquals(0.125, extractor.getThreshold()); |
||||
assertEquals(3, extractor.getNOctaves()); |
||||
assertEquals(5, extractor.getNOctaveLayers()); |
||||
assertEquals(2, extractor.getDiffusivity()); |
||||
} |
||||
|
||||
public void testWriteYml() { |
||||
String filename = OpenCVTestRunner.getTempFileName("yml"); |
||||
|
||||
extractor.write(filename); |
||||
|
||||
String truth = "%YAML:1.0\n---\nformat: 3\nname: \"Feature2D.AKAZE\"\ndescriptor: 5\ndescriptor_channels: 3\ndescriptor_size: 0\nthreshold: 1.0000000474974513e-03\noctaves: 4\nsublevels: 4\ndiffusivity: 1\n"; |
||||
String actual = readFile(filename); |
||||
actual = actual.replaceAll("e([+-])0(\\d\\d)", "e$1$2"); // NOTE: workaround for different platforms double representation
|
||||
assertEquals(truth, actual); |
||||
} |
||||
|
||||
} |
@ -0,0 +1,63 @@ |
||||
package org.opencv.test.features2d; |
||||
|
||||
import org.opencv.test.OpenCVTestCase; |
||||
import org.opencv.test.OpenCVTestRunner; |
||||
import org.opencv.features2d.BRISK; |
||||
|
||||
public class BRISKDescriptorExtractorTest extends OpenCVTestCase { |
||||
|
||||
BRISK extractor; |
||||
|
||||
@Override |
||||
protected void setUp() throws Exception { |
||||
super.setUp(); |
||||
extractor = BRISK.create(); // default (30,3,1)
|
||||
} |
||||
|
||||
public void testCreate() { |
||||
assertNotNull(extractor); |
||||
} |
||||
|
||||
public void testDetectListOfMatListOfListOfKeyPoint() { |
||||
fail("Not yet implemented"); |
||||
} |
||||
|
||||
public void testDetectListOfMatListOfListOfKeyPointListOfMat() { |
||||
fail("Not yet implemented"); |
||||
} |
||||
|
||||
public void testDetectMatListOfKeyPoint() { |
||||
fail("Not yet implemented"); |
||||
} |
||||
|
||||
public void testDetectMatListOfKeyPointMat() { |
||||
fail("Not yet implemented"); |
||||
} |
||||
|
||||
public void testEmpty() { |
||||
fail("Not yet implemented"); |
||||
} |
||||
|
||||
public void testReadYml() { |
||||
String filename = OpenCVTestRunner.getTempFileName("yml"); |
||||
writeFile(filename, "%YAML:1.0\n---\nname: \"Feature2D.BRISK\"\nthreshold: 31\noctaves: 4\npatternScale: 1.1\n"); |
||||
|
||||
extractor.read(filename); |
||||
|
||||
assertEquals(31, extractor.getThreshold()); |
||||
assertEquals(4, extractor.getOctaves()); |
||||
assertEquals(1.1f, extractor.getPatternScale()); |
||||
} |
||||
|
||||
public void testWriteYml() { |
||||
String filename = OpenCVTestRunner.getTempFileName("yml"); |
||||
|
||||
extractor.write(filename); |
||||
|
||||
String truth = "%YAML:1.0\n---\nname: \"Feature2D.BRISK\"\nthreshold: 30\noctaves: 3\npatternScale: 1.\n"; |
||||
String actual = readFile(filename); |
||||
actual = actual.replaceAll("e([+-])0(\\d\\d)", "e$1$2"); // NOTE: workaround for different platforms double representation
|
||||
assertEquals(truth, actual); |
||||
} |
||||
|
||||
} |
@ -0,0 +1,66 @@ |
||||
package org.opencv.test.features2d; |
||||
|
||||
import org.opencv.test.OpenCVTestCase; |
||||
import org.opencv.test.OpenCVTestRunner; |
||||
import org.opencv.features2d.KAZE; |
||||
|
||||
public class KAZEDescriptorExtractorTest extends OpenCVTestCase { |
||||
|
||||
KAZE extractor; |
||||
|
||||
@Override |
||||
protected void setUp() throws Exception { |
||||
super.setUp(); |
||||
extractor = KAZE.create(); // default (false,false,0.001f,4,4,1)
|
||||
} |
||||
|
||||
public void testCreate() { |
||||
assertNotNull(extractor); |
||||
} |
||||
|
||||
public void testDetectListOfMatListOfListOfKeyPoint() { |
||||
fail("Not yet implemented"); |
||||
} |
||||
|
||||
public void testDetectListOfMatListOfListOfKeyPointListOfMat() { |
||||
fail("Not yet implemented"); |
||||
} |
||||
|
||||
public void testDetectMatListOfKeyPoint() { |
||||
fail("Not yet implemented"); |
||||
} |
||||
|
||||
public void testDetectMatListOfKeyPointMat() { |
||||
fail("Not yet implemented"); |
||||
} |
||||
|
||||
public void testEmpty() { |
||||
fail("Not yet implemented"); |
||||
} |
||||
|
||||
public void testReadYml() { |
||||
String filename = OpenCVTestRunner.getTempFileName("yml"); |
||||
writeFile(filename, "%YAML:1.0\n---\nformat: 3\nname: \"Feature2D.KAZE\"\nextended: 1\nupright: 1\nthreshold: 0.125\noctaves: 3\nsublevels: 5\ndiffusivity: 2\n"); |
||||
|
||||
extractor.read(filename); |
||||
|
||||
assertEquals(true, extractor.getExtended()); |
||||
assertEquals(true, extractor.getUpright()); |
||||
assertEquals(0.125, extractor.getThreshold()); |
||||
assertEquals(3, extractor.getNOctaves()); |
||||
assertEquals(5, extractor.getNOctaveLayers()); |
||||
assertEquals(2, extractor.getDiffusivity()); |
||||
} |
||||
|
||||
public void testWriteYml() { |
||||
String filename = OpenCVTestRunner.getTempFileName("yml"); |
||||
|
||||
extractor.write(filename); |
||||
|
||||
String truth = "%YAML:1.0\n---\nformat: 3\nname: \"Feature2D.KAZE\"\nextended: 0\nupright: 0\nthreshold: 1.0000000474974513e-03\noctaves: 4\nsublevels: 4\ndiffusivity: 1\n"; |
||||
String actual = readFile(filename); |
||||
actual = actual.replaceAll("e([+-])0(\\d\\d)", "e$1$2"); // NOTE: workaround for different platforms double representation
|
||||
assertEquals(truth, actual); |
||||
} |
||||
|
||||
} |
@ -1,133 +0,0 @@ |
||||
package org.opencv.test.features2d; |
||||
|
||||
import java.util.Arrays; |
||||
|
||||
import org.opencv.core.CvType; |
||||
import org.opencv.core.Mat; |
||||
import org.opencv.core.MatOfKeyPoint; |
||||
import org.opencv.core.Point; |
||||
import org.opencv.core.Scalar; |
||||
import org.opencv.core.KeyPoint; |
||||
import org.opencv.test.OpenCVTestCase; |
||||
import org.opencv.test.OpenCVTestRunner; |
||||
import org.opencv.imgproc.Imgproc; |
||||
import org.opencv.features2d.Feature2D; |
||||
|
||||
public class STARFeatureDetectorTest extends OpenCVTestCase { |
||||
|
||||
Feature2D detector; |
||||
int matSize; |
||||
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)); |
||||
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); |
||||
return img; |
||||
} |
||||
|
||||
protected void setUp() throws Exception { |
||||
super.setUp(); |
||||
detector = createClassInstance(XFEATURES2D+"StarDetector", DEFAULT_FACTORY, null, null); |
||||
matSize = 200; |
||||
truth = new KeyPoint[] { |
||||
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) |
||||
}; |
||||
} |
||||
|
||||
public void testCreate() { |
||||
assertNotNull(detector); |
||||
} |
||||
|
||||
public void testDetectListOfMatListOfListOfKeyPoint() { |
||||
fail("Not yet implemented"); |
||||
} |
||||
|
||||
public void testDetectListOfMatListOfListOfKeyPointListOfMat() { |
||||
fail("Not yet implemented"); |
||||
} |
||||
|
||||
public void testDetectMatListOfKeyPoint() { |
||||
Mat img = getTestImg(); |
||||
MatOfKeyPoint keypoints = new MatOfKeyPoint(); |
||||
|
||||
detector.detect(img, keypoints); |
||||
|
||||
assertListKeyPointEquals(Arrays.asList(truth), keypoints.toList(), EPS); |
||||
} |
||||
|
||||
public void testDetectMatListOfKeyPointMat() { |
||||
Mat img = getTestImg(); |
||||
Mat mask = getMaskImg(); |
||||
MatOfKeyPoint keypoints = new MatOfKeyPoint(); |
||||
|
||||
detector.detect(img, keypoints, mask); |
||||
|
||||
assertListKeyPointEquals(Arrays.asList(truth[0], truth[2], truth[5], truth[7]), keypoints.toList(), EPS); |
||||
} |
||||
|
||||
public void testEmpty() { |
||||
// assertFalse(detector.empty());
|
||||
fail("Not yet implemented"); |
||||
} |
||||
|
||||
public void testRead() { |
||||
Mat img = getTestImg(); |
||||
|
||||
MatOfKeyPoint keypoints1 = new MatOfKeyPoint(); |
||||
detector.detect(img, keypoints1); |
||||
|
||||
String filename = OpenCVTestRunner.getTempFileName("yml"); |
||||
writeFile(filename, "%YAML:1.0\n---\nmaxSize: 45\nresponseThreshold: 150\nlineThresholdProjected: 10\nlineThresholdBinarized: 8\nsuppressNonmaxSize: 5\n"); |
||||
detector.read(filename); |
||||
|
||||
MatOfKeyPoint keypoints2 = new MatOfKeyPoint(); |
||||
detector.detect(img, keypoints2); |
||||
|
||||
assertTrue(keypoints2.total() <= keypoints1.total()); |
||||
} |
||||
|
||||
public void testWrite() { |
||||
String filename = OpenCVTestRunner.getTempFileName("xml"); |
||||
|
||||
detector.write(filename); |
||||
|
||||
// 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"; |
||||
assertEquals(truth, readFile(filename)); |
||||
} |
||||
|
||||
public void testWriteYml() { |
||||
String filename = OpenCVTestRunner.getTempFileName("yml"); |
||||
|
||||
detector.write(filename); |
||||
|
||||
// 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"; |
||||
assertEquals(truth, readFile(filename)); |
||||
} |
||||
|
||||
} |
@ -1,119 +0,0 @@ |
||||
package org.opencv.test.features2d; |
||||
|
||||
import org.opencv.core.CvType; |
||||
import org.opencv.core.Mat; |
||||
import org.opencv.core.MatOfKeyPoint; |
||||
import org.opencv.core.Point; |
||||
import org.opencv.core.Scalar; |
||||
import org.opencv.core.KeyPoint; |
||||
import org.opencv.test.OpenCVTestCase; |
||||
import org.opencv.test.OpenCVTestRunner; |
||||
import org.opencv.imgproc.Imgproc; |
||||
import org.opencv.features2d.Feature2D; |
||||
|
||||
public class SURFDescriptorExtractorTest extends OpenCVTestCase { |
||||
|
||||
Feature2D extractor; |
||||
int matSize; |
||||
|
||||
private Mat getTestImg() { |
||||
Mat cross = new Mat(matSize, matSize, CvType.CV_8U, new Scalar(255)); |
||||
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); |
||||
|
||||
return cross; |
||||
} |
||||
|
||||
@Override |
||||
protected void setUp() throws Exception { |
||||
super.setUp(); |
||||
|
||||
Class[] cParams = {double.class, int.class, int.class, boolean.class, boolean.class}; |
||||
Object[] oValues = {100, 2, 4, true, false}; |
||||
extractor = createClassInstance(XFEATURES2D+"SURF", DEFAULT_FACTORY, cParams, oValues); |
||||
|
||||
matSize = 100; |
||||
} |
||||
|
||||
public void testComputeListOfMatListOfListOfKeyPointListOfMat() { |
||||
fail("Not yet implemented"); |
||||
} |
||||
|
||||
public void testComputeMatListOfKeyPointMat() { |
||||
KeyPoint point = new KeyPoint(55.775577545166016f, 44.224422454833984f, 16, 9.754629f, 8617.863f, 1, -1); |
||||
MatOfKeyPoint keypoints = new MatOfKeyPoint(point); |
||||
Mat img = getTestImg(); |
||||
Mat descriptors = new Mat(); |
||||
|
||||
extractor.compute(img, keypoints, descriptors); |
||||
|
||||
Mat truth = new Mat(1, 128, CvType.CV_32FC1) { |
||||
{ |
||||
put(0, 0, |
||||
0, 0, 0, 0, 0, 0, 0, 0, 0.058821894, 0.058821894, -0.045962855, 0.046261817, 0.0085156476, |
||||
0.0085754395, -0.0064509804, 0.0064509804, 0.00044069235, 0.00044069235, 0, 0, 0.00025723741, |
||||
0.00025723741, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.00025723741, 0.00025723741, -0.00044069235, |
||||
0.00044069235, 0, 0, 0.36278215, 0.36278215, -0.24688604, 0.26173124, 0.052068226, 0.052662034, |
||||
-0.032815345, 0.032815345, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -0.0064523756, |
||||
0.0064523756, 0.0082002236, 0.0088908644, -0.059001274, 0.059001274, 0.045789491, 0.04648013, |
||||
0.11961588, 0.22789426, -0.01322381, 0.18291828, -0.14042182, 0.23973691, 0.073782086, 0.23769434, |
||||
-0.027880307, 0.027880307, 0.049587864, 0.049587864, -0.33991757, 0.33991757, 0.21437603, 0.21437603, |
||||
-0.0020763327, 0.0020763327, 0.006245892, 0.006245892, -0.04067041, 0.04067041, 0.019361559, |
||||
0.019361559, 0, 0, -0.0035977389, 0.0035977389, 0, 0, -0.00099993451, 0.00099993451, 0.040670406, |
||||
0.040670406, -0.019361559, 0.019361559, 0.006245892, 0.006245892, -0.0020763327, 0.0020763327, |
||||
-0.00034532088, 0.00034532088, 0, 0, 0, 0, 0.00034532088, 0.00034532088, -0.00099993451, |
||||
0.00099993451, 0, 0, 0, 0, 0.0035977389, 0.0035977389 |
||||
); |
||||
} |
||||
}; |
||||
|
||||
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() { |
||||
// assertFalse(extractor.empty());
|
||||
fail("Not yet implemented"); |
||||
} |
||||
|
||||
public void testRead() { |
||||
String filename = OpenCVTestRunner.getTempFileName("yml"); |
||||
writeFile(filename, "%YAML:1.0\n---\nnOctaves: 4\nnOctaveLayers: 2\nextended: 1\nupright: 0\n"); |
||||
|
||||
extractor.read(filename); |
||||
|
||||
assertEquals(128, extractor.descriptorSize()); |
||||
} |
||||
|
||||
public void testWrite() { |
||||
String filename = OpenCVTestRunner.getTempFileName("xml"); |
||||
|
||||
extractor.write(filename); |
||||
|
||||
// String truth = "<?xml version=\"1.0\"?>\n<opencv_storage>\n<name>Feature2D.SURF</name>\n<extended>1</extended>\n<hessianThreshold>100.</hessianThreshold>\n<nOctaveLayers>2</nOctaveLayers>\n<nOctaves>4</nOctaves>\n<upright>0</upright>\n</opencv_storage>\n";
|
||||
String truth = "<?xml version=\"1.0\"?>\n<opencv_storage>\n</opencv_storage>\n"; |
||||
assertEquals(truth, readFile(filename)); |
||||
} |
||||
|
||||
public void testWriteYml() { |
||||
String filename = OpenCVTestRunner.getTempFileName("yml"); |
||||
|
||||
extractor.write(filename); |
||||
|
||||
// String truth = "%YAML:1.0\n---\nname: \"Feature2D.SURF\"\nextended: 1\nhessianThreshold: 100.\nnOctaveLayers: 2\nnOctaves: 4\nupright: 0\n";
|
||||
String truth = "%YAML:1.0\n---\n"; |
||||
assertEquals(truth, readFile(filename)); |
||||
} |
||||
|
||||
} |
@ -1,175 +0,0 @@ |
||||
package org.opencv.test.features2d; |
||||
|
||||
import java.util.ArrayList; |
||||
import java.util.Arrays; |
||||
import java.util.Collections; |
||||
import java.util.Comparator; |
||||
import java.util.List; |
||||
|
||||
import org.opencv.core.CvType; |
||||
import org.opencv.core.Mat; |
||||
import org.opencv.core.MatOfKeyPoint; |
||||
import org.opencv.core.Point; |
||||
import org.opencv.core.Scalar; |
||||
import org.opencv.core.KeyPoint; |
||||
import org.opencv.test.OpenCVTestCase; |
||||
import org.opencv.test.OpenCVTestRunner; |
||||
import org.opencv.imgproc.Imgproc; |
||||
import org.opencv.features2d.Feature2D; |
||||
|
||||
public class SURFFeatureDetectorTest extends OpenCVTestCase { |
||||
|
||||
Feature2D detector; |
||||
int matSize; |
||||
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() { |
||||
Mat cross = new Mat(matSize, matSize, CvType.CV_8U, new Scalar(255)); |
||||
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); |
||||
|
||||
return cross; |
||||
} |
||||
|
||||
private void order(List<KeyPoint> points) { |
||||
Collections.sort(points, new Comparator<KeyPoint>() { |
||||
public int compare(KeyPoint p1, KeyPoint p2) { |
||||
if (p1.angle < p2.angle) |
||||
return -1; |
||||
if (p1.angle > p2.angle) |
||||
return 1; |
||||
return 0; |
||||
} |
||||
}); |
||||
} |
||||
|
||||
@Override |
||||
protected void setUp() throws Exception { |
||||
super.setUp(); |
||||
detector = createClassInstance(XFEATURES2D+"SURF", DEFAULT_FACTORY, null, null); |
||||
matSize = 100; |
||||
truth = new KeyPoint[] { |
||||
new KeyPoint(55.775578f, 55.775578f, 16, 80.245735f, 8617.8633f, 0, -1), |
||||
new KeyPoint(44.224422f, 55.775578f, 16, 170.24574f, 8617.8633f, 0, -1), |
||||
new KeyPoint(44.224422f, 44.224422f, 16, 260.24573f, 8617.8633f, 0, -1), |
||||
new KeyPoint(55.775578f, 44.224422f, 16, 350.24573f, 8617.8633f, 0, -1) |
||||
}; |
||||
} |
||||
|
||||
public void testCreate() { |
||||
assertNotNull(detector); |
||||
} |
||||
|
||||
public void testDetectListOfMatListOfListOfKeyPoint() { |
||||
|
||||
setProperty(detector, "hessianThreshold", "double", 8000); |
||||
setProperty(detector, "nOctaves", "int", 3); |
||||
setProperty(detector, "nOctaveLayers", "int", 4); |
||||
setProperty(detector, "upright", "boolean", false); |
||||
|
||||
List<MatOfKeyPoint> keypoints = new ArrayList<MatOfKeyPoint>(); |
||||
Mat cross = getTestImg(); |
||||
List<Mat> crosses = new ArrayList<Mat>(3); |
||||
crosses.add(cross); |
||||
crosses.add(cross); |
||||
crosses.add(cross); |
||||
|
||||
detector.detect(crosses, keypoints); |
||||
|
||||
assertEquals(3, keypoints.size()); |
||||
|
||||
for (MatOfKeyPoint mkp : keypoints) { |
||||
List<KeyPoint> lkp = mkp.toList(); |
||||
order(lkp); |
||||
assertListKeyPointEquals(Arrays.asList(truth), lkp, EPS); |
||||
} |
||||
} |
||||
|
||||
public void testDetectListOfMatListOfListOfKeyPointListOfMat() { |
||||
fail("Not yet implemented"); |
||||
} |
||||
|
||||
public void testDetectMatListOfKeyPoint() { |
||||
|
||||
setProperty(detector, "hessianThreshold", "double", 8000); |
||||
setProperty(detector, "nOctaves", "int", 3); |
||||
setProperty(detector, "nOctaveLayers", "int", 4); |
||||
setProperty(detector, "upright", "boolean", false); |
||||
|
||||
MatOfKeyPoint keypoints = new MatOfKeyPoint(); |
||||
Mat cross = getTestImg(); |
||||
|
||||
detector.detect(cross, keypoints); |
||||
|
||||
List<KeyPoint> lkp = keypoints.toList(); |
||||
order(lkp); |
||||
assertListKeyPointEquals(Arrays.asList(truth), lkp, EPS); |
||||
} |
||||
|
||||
public void testDetectMatListOfKeyPointMat() { |
||||
|
||||
setProperty(detector, "hessianThreshold", "double", 8000); |
||||
setProperty(detector, "nOctaves", "int", 3); |
||||
setProperty(detector, "nOctaveLayers", "int", 4); |
||||
setProperty(detector, "upright", "boolean", false); |
||||
|
||||
Mat img = getTestImg(); |
||||
Mat mask = getMaskImg(); |
||||
MatOfKeyPoint keypoints = new MatOfKeyPoint(); |
||||
|
||||
detector.detect(img, keypoints, mask); |
||||
|
||||
List<KeyPoint> lkp = keypoints.toList(); |
||||
order(lkp); |
||||
assertListKeyPointEquals(Arrays.asList(truth[1], truth[2]), lkp, EPS); |
||||
} |
||||
|
||||
public void testEmpty() { |
||||
// assertFalse(detector.empty());
|
||||
fail("Not yet implemented"); |
||||
} |
||||
|
||||
public void testRead() { |
||||
Mat cross = getTestImg(); |
||||
|
||||
MatOfKeyPoint keypoints1 = new MatOfKeyPoint(); |
||||
detector.detect(cross, keypoints1); |
||||
|
||||
String filename = OpenCVTestRunner.getTempFileName("yml"); |
||||
writeFile(filename, "%YAML:1.0\n---\nhessianThreshold: 8000.\noctaves: 3\noctaveLayers: 4\nupright: 0\n"); |
||||
detector.read(filename); |
||||
|
||||
MatOfKeyPoint keypoints2 = new MatOfKeyPoint(); |
||||
detector.detect(cross, keypoints2); |
||||
|
||||
assertTrue(keypoints2.total() <= keypoints1.total()); |
||||
} |
||||
|
||||
public void testWrite() { |
||||
String filename = OpenCVTestRunner.getTempFileName("xml"); |
||||
|
||||
detector.write(filename); |
||||
|
||||
// String truth = "<?xml version=\"1.0\"?>\n<opencv_storage>\n<name>Feature2D.SURF</name>\n<extended>0</extended>\n<hessianThreshold>100.</hessianThreshold>\n<nOctaveLayers>3</nOctaveLayers>\n<nOctaves>4</nOctaves>\n<upright>0</upright>\n</opencv_storage>\n";
|
||||
String truth = "<?xml version=\"1.0\"?>\n<opencv_storage>\n</opencv_storage>\n"; |
||||
assertEquals(truth, readFile(filename)); |
||||
} |
||||
|
||||
public void testWriteYml() { |
||||
String filename = OpenCVTestRunner.getTempFileName("yml"); |
||||
|
||||
detector.write(filename); |
||||
|
||||
// String truth = "%YAML:1.0\n---\nname: \"Feature2D.SURF\"\nextended: 0\nhessianThreshold: 100.\nnOctaveLayers: 3\nnOctaves: 4\nupright: 0\n";
|
||||
String truth = "%YAML:1.0\n---\n"; |
||||
assertEquals(truth, readFile(filename)); |
||||
} |
||||
|
||||
} |
Loading…
Reference in new issue