From bb870a8270c14808913e98464fe0d14078d58f11 Mon Sep 17 00:00:00 2001 From: Andrey Pavlenko Date: Mon, 9 Apr 2012 08:20:23 +0000 Subject: [PATCH] Java API: fixing more tests --- .../features2d/FASTFeatureDetectorTest.java | 27 ++++++----- .../FlannBasedDescriptorMatcherTest.java | 38 +++++++-------- .../ORBDescriptorExtractorTest.java | 8 ++-- .../SIFTDescriptorExtractorTest.java | 8 ++-- .../features2d/STARFeatureDetectorTest.java | 21 ++++----- .../SURFDescriptorExtractorTest.java | 6 +-- .../features2d/SURFFeatureDetectorTest.java | 46 ++++++++++--------- 7 files changed, 76 insertions(+), 78 deletions(-) diff --git a/modules/java/android_test/src/org/opencv/test/features2d/FASTFeatureDetectorTest.java b/modules/java/android_test/src/org/opencv/test/features2d/FASTFeatureDetectorTest.java index 9159724bb6..d6cf9cdea1 100644 --- a/modules/java/android_test/src/org/opencv/test/features2d/FASTFeatureDetectorTest.java +++ b/modules/java/android_test/src/org/opencv/test/features2d/FASTFeatureDetectorTest.java @@ -1,8 +1,11 @@ package org.opencv.test.features2d; +import java.util.Arrays; + import org.opencv.core.Core; 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.features2d.FeatureDetector; @@ -10,10 +13,6 @@ import org.opencv.features2d.KeyPoint; import org.opencv.test.OpenCVTestCase; import org.opencv.test.OpenCVTestRunner; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; - public class FASTFeatureDetectorTest extends OpenCVTestCase { FeatureDetector detector; @@ -56,11 +55,11 @@ public class FASTFeatureDetectorTest extends OpenCVTestCase { public void testDetectMatListOfKeyPoint() { Mat img = getTestImg(); - List keypoints = new ArrayList(); + MatOfKeyPoint keypoints = new MatOfKeyPoint(); detector.detect(img, keypoints); - assertListKeyPointEquals(Arrays.asList(truth), keypoints, EPS); + assertListKeyPointEquals(Arrays.asList(truth), keypoints.toList(), EPS); // OpenCVTestRunner.Log("points found: " + keypoints.size()); // for (KeyPoint kp : keypoints) @@ -70,11 +69,11 @@ public class FASTFeatureDetectorTest extends OpenCVTestCase { public void testDetectMatListOfKeyPointMat() { Mat img = getTestImg(); Mat mask = getMaskImg(); - List keypoints = new ArrayList(); + MatOfKeyPoint keypoints = new MatOfKeyPoint(); detector.detect(img, keypoints, mask); - assertListKeyPointEquals(Arrays.asList(truth[0], truth[1]), keypoints, EPS); + assertListKeyPointEquals(Arrays.asList(truth[0], truth[1]), keypoints.toList(), EPS); } public void testEmpty() { @@ -87,18 +86,18 @@ public class FASTFeatureDetectorTest extends OpenCVTestCase { writeFile(filename, "%YAML:1.0\nthreshold: 130\nnonmaxSuppression: 1\n"); detector.read(filename); - List keypoints1 = new ArrayList(); + MatOfKeyPoint keypoints1 = new MatOfKeyPoint(); detector.detect(grayChess, keypoints1); writeFile(filename, "%YAML:1.0\nthreshold: 150\nnonmaxSuppression: 1\n"); detector.read(filename); - List keypoints2 = new ArrayList(); + MatOfKeyPoint keypoints2 = new MatOfKeyPoint(); detector.detect(grayChess, keypoints2); - assertTrue(keypoints2.size() <= keypoints1.size()); + assertTrue(keypoints2.total() <= keypoints1.total()); } public void testReadYml() { @@ -108,7 +107,7 @@ public class FASTFeatureDetectorTest extends OpenCVTestCase { "\n\n130\n1\n\n"); detector.read(filename); - List keypoints1 = new ArrayList(); + MatOfKeyPoint keypoints1 = new MatOfKeyPoint(); detector.detect(grayChess, keypoints1); @@ -116,11 +115,11 @@ public class FASTFeatureDetectorTest extends OpenCVTestCase { "\n\n150\n1\n\n"); detector.read(filename); - List keypoints2 = new ArrayList(); + MatOfKeyPoint keypoints2 = new MatOfKeyPoint(); detector.detect(grayChess, keypoints2); - assertTrue(keypoints2.size() <= keypoints1.size()); + assertTrue(keypoints2.total() <= keypoints1.total()); } public void testWrite() { diff --git a/modules/java/android_test/src/org/opencv/test/features2d/FlannBasedDescriptorMatcherTest.java b/modules/java/android_test/src/org/opencv/test/features2d/FlannBasedDescriptorMatcherTest.java index 21485b3f3d..a261c5b2a4 100644 --- a/modules/java/android_test/src/org/opencv/test/features2d/FlannBasedDescriptorMatcherTest.java +++ b/modules/java/android_test/src/org/opencv/test/features2d/FlannBasedDescriptorMatcherTest.java @@ -1,9 +1,14 @@ package org.opencv.test.features2d; +import java.util.Arrays; +import java.util.List; + import org.opencv.core.Core; import org.opencv.core.CvException; import org.opencv.core.CvType; import org.opencv.core.Mat; +import org.opencv.core.MatOfDMatch; +import org.opencv.core.MatOfKeyPoint; import org.opencv.core.Point; import org.opencv.core.Scalar; import org.opencv.features2d.DMatch; @@ -14,10 +19,6 @@ import org.opencv.features2d.KeyPoint; import org.opencv.test.OpenCVTestCase; import org.opencv.test.OpenCVTestRunner; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; - public class FlannBasedDescriptorMatcherTest extends OpenCVTestCase { static final String xmlParamsDefault = "\n" @@ -109,7 +110,7 @@ public class FlannBasedDescriptorMatcherTest extends OpenCVTestCase { } private Mat getBriefTestDescriptors(Mat img) { - List keypoints = new ArrayList(); + MatOfKeyPoint keypoints = new MatOfKeyPoint(); Mat descriptors = new Mat(); FeatureDetector detector = FeatureDetector.create(FeatureDetector.FAST); @@ -141,7 +142,7 @@ public class FlannBasedDescriptorMatcherTest extends OpenCVTestCase { private Mat getQueryDescriptors() { Mat img = getQueryImg(); - List keypoints = new ArrayList(); + MatOfKeyPoint keypoints = new MatOfKeyPoint(); Mat descriptors = new Mat(); FeatureDetector detector = FeatureDetector.create(FeatureDetector.SURF); @@ -167,7 +168,7 @@ public class FlannBasedDescriptorMatcherTest extends OpenCVTestCase { private Mat getTrainDescriptors() { Mat img = getTrainImg(); - List keypoints = Arrays.asList(new KeyPoint(50, 50, 16, 0, 20000, 1, -1), new KeyPoint(42, 42, 16, 160, 10000, 1, -1)); + MatOfKeyPoint keypoints = new MatOfKeyPoint(new KeyPoint(50, 50, 16, 0, 20000, 1, -1), new KeyPoint(42, 42, 16, 160, 10000, 1, -1)); Mat descriptors = new Mat(); DescriptorExtractor extractor = DescriptorExtractor.create(DescriptorExtractor.SURF); @@ -283,36 +284,36 @@ public class FlannBasedDescriptorMatcherTest extends OpenCVTestCase { public void testMatchMatListOfDMatch() { Mat train = getTrainDescriptors(); Mat query = getQueryDescriptors(); - List matches = new ArrayList(); + MatOfDMatch matches = new MatOfDMatch(); matcher.add(Arrays.asList(train)); matcher.train(); matcher.match(query, matches); - assertListDMatchEquals(Arrays.asList(truth), matches, EPS); + assertArrayDMatchEquals(truth, matches.toArray(), EPS); } public void testMatchMatListOfDMatchListOfMat() { Mat train = getTrainDescriptors(); Mat query = getQueryDescriptors(); Mat mask = getMaskImg(); - List matches = new ArrayList(); + MatOfDMatch matches = new MatOfDMatch(); matcher.add(Arrays.asList(train)); matcher.train(); matcher.match(query, matches, Arrays.asList(mask)); - assertListDMatchEquals(Arrays.asList(truth), matches, EPS); + assertArrayDMatchEquals(truth, matches.toArray(), EPS); } public void testMatchMatMatListOfDMatch() { Mat train = getTrainDescriptors(); Mat query = getQueryDescriptors(); - List matches = new ArrayList(); + MatOfDMatch matches = new MatOfDMatch(); matcher.match(query, train, matches); - assertListDMatchEquals(Arrays.asList(truth), matches, EPS); + assertArrayDMatchEquals(truth, matches.toArray(), EPS); // OpenCVTestRunner.Log("matches found: " + matches.size()); // for (DMatch m : matches) @@ -323,11 +324,11 @@ public class FlannBasedDescriptorMatcherTest extends OpenCVTestCase { Mat train = getTrainDescriptors(); Mat query = getQueryDescriptors(); Mat mask = getMaskImg(); - List matches = new ArrayList(); + MatOfDMatch matches = new MatOfDMatch(); matcher.match(query, train, matches, mask); - assertListDMatchEquals(Arrays.asList(truth), matches, EPS); + assertListDMatchEquals(Arrays.asList(truth), matches.toList(), EPS); } public void testRadiusMatchMatListOfListOfDMatchFloat() { @@ -362,14 +363,15 @@ public class FlannBasedDescriptorMatcherTest extends OpenCVTestCase { Mat train = getBriefTrainDescriptors(); Mat query = getBriefQueryDescriptors(); - List matches = new ArrayList(); + MatOfDMatch matches = new MatOfDMatch(); matcher.match(query, train, matches); - assertListDMatchEquals(Arrays.asList(new DMatch(0, 0, 0, 0), + assertArrayDMatchEquals(new DMatch[]{ + new DMatch(0, 0, 0, 0), new DMatch(1, 2, 0, 0), new DMatch(2, 1, 0, 0), - new DMatch(3, 3, 0, 0)), matches, EPS); + new DMatch(3, 3, 0, 0)}, matches.toArray(), EPS); } public void testTrain() { diff --git a/modules/java/android_test/src/org/opencv/test/features2d/ORBDescriptorExtractorTest.java b/modules/java/android_test/src/org/opencv/test/features2d/ORBDescriptorExtractorTest.java index 0e46a0dbd3..5f9874ec78 100644 --- a/modules/java/android_test/src/org/opencv/test/features2d/ORBDescriptorExtractorTest.java +++ b/modules/java/android_test/src/org/opencv/test/features2d/ORBDescriptorExtractorTest.java @@ -3,6 +3,7 @@ package org.opencv.test.features2d; import org.opencv.core.Core; 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.features2d.DescriptorExtractor; @@ -10,9 +11,6 @@ import org.opencv.features2d.KeyPoint; import org.opencv.test.OpenCVTestCase; import org.opencv.test.OpenCVTestRunner; -import java.util.Arrays; -import java.util.List; - public class ORBDescriptorExtractorTest extends OpenCVTestCase { DescriptorExtractor extractor; @@ -40,7 +38,7 @@ public class ORBDescriptorExtractorTest extends OpenCVTestCase { public void testComputeMatListOfKeyPointMat() { KeyPoint point = new KeyPoint(55.775577545166016f, 44.224422454833984f, 16, 9.754629f, 8617.863f, 1, -1); - List keypoints = Arrays.asList(point); + MatOfKeyPoint keypoints = new MatOfKeyPoint(point); Mat img = getTestImg(); Mat descriptors = new Mat(); @@ -73,7 +71,7 @@ public class ORBDescriptorExtractorTest extends OpenCVTestCase { public void testRead() { KeyPoint point = new KeyPoint(55.775577545166016f, 44.224422454833984f, 16, 9.754629f, 8617.863f, 1, -1); - List keypoints = Arrays.asList(point); + MatOfKeyPoint keypoints = new MatOfKeyPoint(point); Mat img = getTestImg(); Mat descriptors = new Mat(); diff --git a/modules/java/android_test/src/org/opencv/test/features2d/SIFTDescriptorExtractorTest.java b/modules/java/android_test/src/org/opencv/test/features2d/SIFTDescriptorExtractorTest.java index b9d720cb6e..d6512aa1f3 100644 --- a/modules/java/android_test/src/org/opencv/test/features2d/SIFTDescriptorExtractorTest.java +++ b/modules/java/android_test/src/org/opencv/test/features2d/SIFTDescriptorExtractorTest.java @@ -3,6 +3,7 @@ package org.opencv.test.features2d; import org.opencv.core.Core; 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.features2d.DescriptorExtractor; @@ -10,9 +11,6 @@ import org.opencv.features2d.KeyPoint; import org.opencv.test.OpenCVTestCase; import org.opencv.test.OpenCVTestRunner; -import java.util.Arrays; -import java.util.List; - public class SIFTDescriptorExtractorTest extends OpenCVTestCase { DescriptorExtractor extractor; @@ -50,7 +48,7 @@ public class SIFTDescriptorExtractorTest extends OpenCVTestCase { } public void testComputeMatListOfKeyPointMat() { - List keypoints = Arrays.asList(keypoint); + MatOfKeyPoint keypoints = new MatOfKeyPoint(keypoint); Mat img = getTestImg(); Mat descriptors = new Mat(); @@ -76,7 +74,7 @@ public class SIFTDescriptorExtractorTest extends OpenCVTestCase { } public void testRead() { - List keypoints = Arrays.asList(keypoint); + MatOfKeyPoint keypoints =new MatOfKeyPoint(keypoint); Mat img = getTestImg(); Mat descriptors = new Mat(); diff --git a/modules/java/android_test/src/org/opencv/test/features2d/STARFeatureDetectorTest.java b/modules/java/android_test/src/org/opencv/test/features2d/STARFeatureDetectorTest.java index 768bd89d33..8342eedfd3 100644 --- a/modules/java/android_test/src/org/opencv/test/features2d/STARFeatureDetectorTest.java +++ b/modules/java/android_test/src/org/opencv/test/features2d/STARFeatureDetectorTest.java @@ -1,8 +1,11 @@ package org.opencv.test.features2d; +import java.util.Arrays; + import org.opencv.core.Core; 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.features2d.FeatureDetector; @@ -10,10 +13,6 @@ import org.opencv.features2d.KeyPoint; import org.opencv.test.OpenCVTestCase; import org.opencv.test.OpenCVTestRunner; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; - public class STARFeatureDetectorTest extends OpenCVTestCase { FeatureDetector detector; @@ -75,21 +74,21 @@ public class STARFeatureDetectorTest extends OpenCVTestCase { public void testDetectMatListOfKeyPoint() { Mat img = getTestImg(); - List keypoints = new ArrayList(); + MatOfKeyPoint keypoints = new MatOfKeyPoint(); detector.detect(img, keypoints); - assertListKeyPointEquals(Arrays.asList(truth), keypoints, EPS); + assertListKeyPointEquals(Arrays.asList(truth), keypoints.toList(), EPS); } public void testDetectMatListOfKeyPointMat() { Mat img = getTestImg(); Mat mask = getMaskImg(); - List keypoints = new ArrayList(); + MatOfKeyPoint keypoints = new MatOfKeyPoint(); detector.detect(img, keypoints, mask); - assertListKeyPointEquals(Arrays.asList(truth[0], truth[2], truth[5], truth[7]), keypoints, EPS); + assertListKeyPointEquals(Arrays.asList(truth[0], truth[2], truth[5], truth[7]), keypoints.toList(), EPS); } public void testEmpty() { @@ -99,17 +98,17 @@ public class STARFeatureDetectorTest extends OpenCVTestCase { public void testRead() { Mat img = getTestImg(); - List keypoints1 = new ArrayList(); + MatOfKeyPoint keypoints1 = new MatOfKeyPoint(); detector.detect(img, keypoints1); String filename = OpenCVTestRunner.getTempFileName("yml"); writeFile(filename, "%YAML:1.0\nmaxSize: 45\nresponseThreshold: 150\nlineThresholdProjected: 10\nlineThresholdBinarized: 8\nsuppressNonmaxSize: 5\n"); detector.read(filename); - List keypoints2 = new ArrayList(); + MatOfKeyPoint keypoints2 = new MatOfKeyPoint(); detector.detect(img, keypoints2); - assertTrue(keypoints2.size() <= keypoints1.size()); + assertTrue(keypoints2.total() <= keypoints1.total()); } public void testWrite() { diff --git a/modules/java/android_test/src/org/opencv/test/features2d/SURFDescriptorExtractorTest.java b/modules/java/android_test/src/org/opencv/test/features2d/SURFDescriptorExtractorTest.java index f057ef02b0..bb226a8f74 100644 --- a/modules/java/android_test/src/org/opencv/test/features2d/SURFDescriptorExtractorTest.java +++ b/modules/java/android_test/src/org/opencv/test/features2d/SURFDescriptorExtractorTest.java @@ -3,6 +3,7 @@ package org.opencv.test.features2d; import org.opencv.core.Core; 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.features2d.DescriptorExtractor; @@ -10,9 +11,6 @@ import org.opencv.features2d.KeyPoint; import org.opencv.test.OpenCVTestCase; import org.opencv.test.OpenCVTestRunner; -import java.util.Arrays; -import java.util.List; - public class SURFDescriptorExtractorTest extends OpenCVTestCase { DescriptorExtractor extractor; @@ -40,7 +38,7 @@ public class SURFDescriptorExtractorTest extends OpenCVTestCase { public void testComputeMatListOfKeyPointMat() { KeyPoint point = new KeyPoint(55.775577545166016f, 44.224422454833984f, 16, 9.754629f, 8617.863f, 1, -1); - List keypoints = Arrays.asList(point); + MatOfKeyPoint keypoints = new MatOfKeyPoint(point); Mat img = getTestImg(); Mat descriptors = new Mat(); diff --git a/modules/java/android_test/src/org/opencv/test/features2d/SURFFeatureDetectorTest.java b/modules/java/android_test/src/org/opencv/test/features2d/SURFFeatureDetectorTest.java index 03bcd8b05d..82943dad57 100644 --- a/modules/java/android_test/src/org/opencv/test/features2d/SURFFeatureDetectorTest.java +++ b/modules/java/android_test/src/org/opencv/test/features2d/SURFFeatureDetectorTest.java @@ -1,21 +1,22 @@ package org.opencv.test.features2d; -import org.opencv.core.Core; -import org.opencv.core.CvType; -import org.opencv.core.Mat; -import org.opencv.core.Point; -import org.opencv.core.Scalar; -import org.opencv.features2d.FeatureDetector; -import org.opencv.features2d.KeyPoint; -import org.opencv.test.OpenCVTestCase; -import org.opencv.test.OpenCVTestRunner; - import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.Comparator; import java.util.List; +import org.opencv.core.Core; +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.features2d.FeatureDetector; +import org.opencv.features2d.KeyPoint; +import org.opencv.test.OpenCVTestCase; +import org.opencv.test.OpenCVTestRunner; + public class SURFFeatureDetectorTest extends OpenCVTestCase { FeatureDetector detector; @@ -72,7 +73,7 @@ public class SURFFeatureDetectorTest extends OpenCVTestCase { writeFile(filename, "%YAML:1.0\nhessianThreshold: 8000.\noctaves: 3\noctaveLayers: 4\nupright: 0\n"); detector.read(filename); - List> keypoints = new ArrayList>(); + List keypoints = new ArrayList(); Mat cross = getTestImg(); List crosses = new ArrayList(3); crosses.add(cross); @@ -83,7 +84,8 @@ public class SURFFeatureDetectorTest extends OpenCVTestCase { assertEquals(3, keypoints.size()); - for (List lkp : keypoints) { + for (MatOfKeyPoint mkp : keypoints) { + List lkp = mkp.toList(); order(lkp); assertListKeyPointEquals(Arrays.asList(truth), lkp, EPS); } @@ -98,13 +100,14 @@ public class SURFFeatureDetectorTest extends OpenCVTestCase { writeFile(filename, "%YAML:1.0\nhessianThreshold: 8000.\noctaves: 3\noctaveLayers: 4\nupright: 0\n"); detector.read(filename); - List keypoints = new ArrayList(); + MatOfKeyPoint keypoints = new MatOfKeyPoint(); Mat cross = getTestImg(); detector.detect(cross, keypoints); - order(keypoints); - assertListKeyPointEquals(Arrays.asList(truth), keypoints, EPS); + List lkp = keypoints.toList(); + order(lkp); + assertListKeyPointEquals(Arrays.asList(truth), lkp, EPS); } public void testDetectMatListOfKeyPointMat() { @@ -114,12 +117,13 @@ public class SURFFeatureDetectorTest extends OpenCVTestCase { Mat img = getTestImg(); Mat mask = getMaskImg(); - List keypoints = new ArrayList(); + MatOfKeyPoint keypoints = new MatOfKeyPoint(); detector.detect(img, keypoints, mask); - order(keypoints); - assertListKeyPointEquals(Arrays.asList(truth[1], truth[2]), keypoints, EPS); + List lkp = keypoints.toList(); + order(lkp); + assertListKeyPointEquals(Arrays.asList(truth[1], truth[2]), lkp, EPS); } public void testEmpty() { @@ -129,17 +133,17 @@ public class SURFFeatureDetectorTest extends OpenCVTestCase { public void testRead() { Mat cross = getTestImg(); - List keypoints1 = new ArrayList(); + MatOfKeyPoint keypoints1 = new MatOfKeyPoint(); detector.detect(cross, keypoints1); String filename = OpenCVTestRunner.getTempFileName("yml"); writeFile(filename, "%YAML:1.0\nhessianThreshold: 8000.\noctaves: 3\noctaveLayers: 4\nupright: 0\n"); detector.read(filename); - List keypoints2 = new ArrayList(); + MatOfKeyPoint keypoints2 = new MatOfKeyPoint(); detector.detect(cross, keypoints2); - assertTrue(keypoints2.size() <= keypoints1.size()); + assertTrue(keypoints2.total() <= keypoints1.total()); } public void testWrite() {