1
0
mirror of https://github.com/opencv/opencv.git synced 2026-07-28 23:03:03 +04:00

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 CMake
This commit is contained in:
augustinmanecy
2022-12-21 14:03:00 +01:00
committed by GitHub
parent 63b6b24cd0
commit 0bd54a60e9
28 changed files with 845 additions and 555 deletions
@@ -8,7 +8,6 @@ import org.opencv.core.Mat;
import org.opencv.core.MatOfKeyPoint;
import org.opencv.core.Point;
import org.opencv.core.Scalar;
import org.opencv.features2d.Feature2D;
import org.opencv.features2d.FastFeatureDetector;
import org.opencv.core.KeyPoint;
import org.opencv.test.OpenCVTestCase;
@@ -17,7 +16,7 @@ import org.opencv.imgproc.Imgproc;
public class FASTFeatureDetectorTest extends OpenCVTestCase {
Feature2D detector;
FastFeatureDetector detector;
KeyPoint[] truth;
private Mat getMaskImg() {
@@ -78,20 +77,24 @@ public class FASTFeatureDetectorTest extends OpenCVTestCase {
public void testEmpty() {
// assertFalse(detector.empty());
fail("Not yet implemented"); //FAST does not override empty() method
fail("Not yet implemented"); // FAST does not override empty() method
}
public void testRead() {
String filename = OpenCVTestRunner.getTempFileName("yml");
String filename = OpenCVTestRunner.getTempFileName("xml");
writeFile(filename, "%YAML:1.0\n---\nthreshold: 130\nnonmaxSuppression: 1\n");
writeFile(filename, "<?xml version=\"1.0\"?>\n<opencv_storage>\n<name>Feature2D.FastFeatureDetector</name>\n<threshold>10</threshold>\n<nonmaxSuppression>1</nonmaxSuppression>\n<type>2</type>\n</opencv_storage>\n");
detector.read(filename);
assertEquals(10, detector.getThreshold());
assertEquals(true, detector.getNonmaxSuppression());
assertEquals(2, detector.getType());
MatOfKeyPoint keypoints1 = new MatOfKeyPoint();
detector.detect(grayChess, keypoints1);
writeFile(filename, "%YAML:1.0\n---\nthreshold: 150\nnonmaxSuppression: 1\n");
writeFile(filename, "<?xml version=\"1.0\"?>\n<opencv_storage>\n<name>Feature2D.FastFeatureDetector</name>\n<threshold>150</threshold>\n<nonmaxSuppression>1</nonmaxSuppression>\n<type>2</type>\n</opencv_storage>\n");
detector.read(filename);
MatOfKeyPoint keypoints2 = new MatOfKeyPoint();
@@ -104,16 +107,18 @@ public class FASTFeatureDetectorTest extends OpenCVTestCase {
public void testReadYml() {
String filename = OpenCVTestRunner.getTempFileName("yml");
writeFile(filename,
"<?xml version=\"1.0\"?>\n<opencv_storage>\n<threshold>130</threshold>\n<nonmaxSuppression>1</nonmaxSuppression>\n</opencv_storage>\n");
writeFile(filename, "%YAML:1.0\n---\nthreshold: 130\nnonmaxSuppression: 1\ntype: 2\n");
detector.read(filename);
assertEquals(130, detector.getThreshold());
assertEquals(true, detector.getNonmaxSuppression());
assertEquals(2, detector.getType());
MatOfKeyPoint keypoints1 = new MatOfKeyPoint();
detector.detect(grayChess, keypoints1);
writeFile(filename,
"<?xml version=\"1.0\"?>\n<opencv_storage>\n<threshold>150</threshold>\n<nonmaxSuppression>1</nonmaxSuppression>\n</opencv_storage>\n");
writeFile(filename, "%YAML:1.0\n---\nthreshold: 150\nnonmaxSuppression: 1\ntype: 2\n");
detector.read(filename);
MatOfKeyPoint keypoints2 = new MatOfKeyPoint();
@@ -123,28 +128,14 @@ public class FASTFeatureDetectorTest extends OpenCVTestCase {
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.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";
String data = readFile(filename);
//Log.d("qqq", "\"" + data + "\"");
assertEquals(truth, data);
}
public void testWriteYml() {
String filename = OpenCVTestRunner.getTempFileName("yml");
detector.write(filename);
// String truth = "%YAML:1.0\n---\nname: \"Feature2D.FAST\"\nnonmaxSuppression: 1\nthreshold: 10\ntype: 2\n";
String truth = "%YAML:1.0\n---\n";
String truth = "%YAML:1.0\n---\nname: \"Feature2D.FastFeatureDetector\"\nthreshold: 10\nnonmaxSuppression: 1\ntype: 2\n";
String data = readFile(filename);
//Log.d("qqq", "\"" + data + "\"");
assertEquals(truth, data);
}
}