Commit bb870a82 authored by Andrey Pavlenko's avatar Andrey Pavlenko

Java API: fixing more tests

parent 2e7a9041
package org.opencv.test.features2d; package org.opencv.test.features2d;
import java.util.Arrays;
import org.opencv.core.Core; import org.opencv.core.Core;
import org.opencv.core.CvType; import org.opencv.core.CvType;
import org.opencv.core.Mat; import org.opencv.core.Mat;
import org.opencv.core.MatOfKeyPoint;
import org.opencv.core.Point; import org.opencv.core.Point;
import org.opencv.core.Scalar; import org.opencv.core.Scalar;
import org.opencv.features2d.FeatureDetector; import org.opencv.features2d.FeatureDetector;
...@@ -10,10 +13,6 @@ import org.opencv.features2d.KeyPoint; ...@@ -10,10 +13,6 @@ import org.opencv.features2d.KeyPoint;
import org.opencv.test.OpenCVTestCase; import org.opencv.test.OpenCVTestCase;
import org.opencv.test.OpenCVTestRunner; import org.opencv.test.OpenCVTestRunner;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
public class FASTFeatureDetectorTest extends OpenCVTestCase { public class FASTFeatureDetectorTest extends OpenCVTestCase {
FeatureDetector detector; FeatureDetector detector;
...@@ -56,11 +55,11 @@ public class FASTFeatureDetectorTest extends OpenCVTestCase { ...@@ -56,11 +55,11 @@ public class FASTFeatureDetectorTest extends OpenCVTestCase {
public void testDetectMatListOfKeyPoint() { public void testDetectMatListOfKeyPoint() {
Mat img = getTestImg(); Mat img = getTestImg();
List<KeyPoint> keypoints = new ArrayList<KeyPoint>(); MatOfKeyPoint keypoints = new MatOfKeyPoint();
detector.detect(img, keypoints); detector.detect(img, keypoints);
assertListKeyPointEquals(Arrays.asList(truth), keypoints, EPS); assertListKeyPointEquals(Arrays.asList(truth), keypoints.toList(), EPS);
// OpenCVTestRunner.Log("points found: " + keypoints.size()); // OpenCVTestRunner.Log("points found: " + keypoints.size());
// for (KeyPoint kp : keypoints) // for (KeyPoint kp : keypoints)
...@@ -70,11 +69,11 @@ public class FASTFeatureDetectorTest extends OpenCVTestCase { ...@@ -70,11 +69,11 @@ public class FASTFeatureDetectorTest extends OpenCVTestCase {
public void testDetectMatListOfKeyPointMat() { public void testDetectMatListOfKeyPointMat() {
Mat img = getTestImg(); Mat img = getTestImg();
Mat mask = getMaskImg(); Mat mask = getMaskImg();
List<KeyPoint> keypoints = new ArrayList<KeyPoint>(); MatOfKeyPoint keypoints = new MatOfKeyPoint();
detector.detect(img, keypoints, mask); 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() { public void testEmpty() {
...@@ -87,18 +86,18 @@ public class FASTFeatureDetectorTest extends OpenCVTestCase { ...@@ -87,18 +86,18 @@ public class FASTFeatureDetectorTest extends OpenCVTestCase {
writeFile(filename, "%YAML:1.0\nthreshold: 130\nnonmaxSuppression: 1\n"); writeFile(filename, "%YAML:1.0\nthreshold: 130\nnonmaxSuppression: 1\n");
detector.read(filename); detector.read(filename);
List<KeyPoint> keypoints1 = new ArrayList<KeyPoint>(); MatOfKeyPoint keypoints1 = new MatOfKeyPoint();
detector.detect(grayChess, keypoints1); detector.detect(grayChess, keypoints1);
writeFile(filename, "%YAML:1.0\nthreshold: 150\nnonmaxSuppression: 1\n"); writeFile(filename, "%YAML:1.0\nthreshold: 150\nnonmaxSuppression: 1\n");
detector.read(filename); detector.read(filename);
List<KeyPoint> keypoints2 = new ArrayList<KeyPoint>(); MatOfKeyPoint keypoints2 = new MatOfKeyPoint();
detector.detect(grayChess, keypoints2); detector.detect(grayChess, keypoints2);
assertTrue(keypoints2.size() <= keypoints1.size()); assertTrue(keypoints2.total() <= keypoints1.total());
} }
public void testReadYml() { public void testReadYml() {
...@@ -108,7 +107,7 @@ public class FASTFeatureDetectorTest extends OpenCVTestCase { ...@@ -108,7 +107,7 @@ public class FASTFeatureDetectorTest extends OpenCVTestCase {
"<?xml version=\"1.0\"?>\n<opencv_storage>\n<threshold>130</threshold>\n<nonmaxSuppression>1</nonmaxSuppression>\n</opencv_storage>\n"); "<?xml version=\"1.0\"?>\n<opencv_storage>\n<threshold>130</threshold>\n<nonmaxSuppression>1</nonmaxSuppression>\n</opencv_storage>\n");
detector.read(filename); detector.read(filename);
List<KeyPoint> keypoints1 = new ArrayList<KeyPoint>(); MatOfKeyPoint keypoints1 = new MatOfKeyPoint();
detector.detect(grayChess, keypoints1); detector.detect(grayChess, keypoints1);
...@@ -116,11 +115,11 @@ public class FASTFeatureDetectorTest extends OpenCVTestCase { ...@@ -116,11 +115,11 @@ public class FASTFeatureDetectorTest extends OpenCVTestCase {
"<?xml version=\"1.0\"?>\n<opencv_storage>\n<threshold>150</threshold>\n<nonmaxSuppression>1</nonmaxSuppression>\n</opencv_storage>\n"); "<?xml version=\"1.0\"?>\n<opencv_storage>\n<threshold>150</threshold>\n<nonmaxSuppression>1</nonmaxSuppression>\n</opencv_storage>\n");
detector.read(filename); detector.read(filename);
List<KeyPoint> keypoints2 = new ArrayList<KeyPoint>(); MatOfKeyPoint keypoints2 = new MatOfKeyPoint();
detector.detect(grayChess, keypoints2); detector.detect(grayChess, keypoints2);
assertTrue(keypoints2.size() <= keypoints1.size()); assertTrue(keypoints2.total() <= keypoints1.total());
} }
public void testWrite() { public void testWrite() {
......
package org.opencv.test.features2d; package org.opencv.test.features2d;
import java.util.Arrays;
import java.util.List;
import org.opencv.core.Core; import org.opencv.core.Core;
import org.opencv.core.CvException; import org.opencv.core.CvException;
import org.opencv.core.CvType; import org.opencv.core.CvType;
import org.opencv.core.Mat; import org.opencv.core.Mat;
import org.opencv.core.MatOfDMatch;
import org.opencv.core.MatOfKeyPoint;
import org.opencv.core.Point; import org.opencv.core.Point;
import org.opencv.core.Scalar; import org.opencv.core.Scalar;
import org.opencv.features2d.DMatch; import org.opencv.features2d.DMatch;
...@@ -14,10 +19,6 @@ import org.opencv.features2d.KeyPoint; ...@@ -14,10 +19,6 @@ import org.opencv.features2d.KeyPoint;
import org.opencv.test.OpenCVTestCase; import org.opencv.test.OpenCVTestCase;
import org.opencv.test.OpenCVTestRunner; import org.opencv.test.OpenCVTestRunner;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
public class FlannBasedDescriptorMatcherTest extends OpenCVTestCase { public class FlannBasedDescriptorMatcherTest extends OpenCVTestCase {
static final String xmlParamsDefault = "<?xml version=\"1.0\"?>\n" static final String xmlParamsDefault = "<?xml version=\"1.0\"?>\n"
...@@ -109,7 +110,7 @@ public class FlannBasedDescriptorMatcherTest extends OpenCVTestCase { ...@@ -109,7 +110,7 @@ public class FlannBasedDescriptorMatcherTest extends OpenCVTestCase {
} }
private Mat getBriefTestDescriptors(Mat img) { private Mat getBriefTestDescriptors(Mat img) {
List<KeyPoint> keypoints = new ArrayList<KeyPoint>(); MatOfKeyPoint keypoints = new MatOfKeyPoint();
Mat descriptors = new Mat(); Mat descriptors = new Mat();
FeatureDetector detector = FeatureDetector.create(FeatureDetector.FAST); FeatureDetector detector = FeatureDetector.create(FeatureDetector.FAST);
...@@ -141,7 +142,7 @@ public class FlannBasedDescriptorMatcherTest extends OpenCVTestCase { ...@@ -141,7 +142,7 @@ public class FlannBasedDescriptorMatcherTest extends OpenCVTestCase {
private Mat getQueryDescriptors() { private Mat getQueryDescriptors() {
Mat img = getQueryImg(); Mat img = getQueryImg();
List<KeyPoint> keypoints = new ArrayList<KeyPoint>(); MatOfKeyPoint keypoints = new MatOfKeyPoint();
Mat descriptors = new Mat(); Mat descriptors = new Mat();
FeatureDetector detector = FeatureDetector.create(FeatureDetector.SURF); FeatureDetector detector = FeatureDetector.create(FeatureDetector.SURF);
...@@ -167,7 +168,7 @@ public class FlannBasedDescriptorMatcherTest extends OpenCVTestCase { ...@@ -167,7 +168,7 @@ public class FlannBasedDescriptorMatcherTest extends OpenCVTestCase {
private Mat getTrainDescriptors() { private Mat getTrainDescriptors() {
Mat img = getTrainImg(); Mat img = getTrainImg();
List<KeyPoint> 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(); Mat descriptors = new Mat();
DescriptorExtractor extractor = DescriptorExtractor.create(DescriptorExtractor.SURF); DescriptorExtractor extractor = DescriptorExtractor.create(DescriptorExtractor.SURF);
...@@ -283,36 +284,36 @@ public class FlannBasedDescriptorMatcherTest extends OpenCVTestCase { ...@@ -283,36 +284,36 @@ public class FlannBasedDescriptorMatcherTest extends OpenCVTestCase {
public void testMatchMatListOfDMatch() { public void testMatchMatListOfDMatch() {
Mat train = getTrainDescriptors(); Mat train = getTrainDescriptors();
Mat query = getQueryDescriptors(); Mat query = getQueryDescriptors();
List<DMatch> matches = new ArrayList<DMatch>(); MatOfDMatch matches = new MatOfDMatch();
matcher.add(Arrays.asList(train)); matcher.add(Arrays.asList(train));
matcher.train(); matcher.train();
matcher.match(query, matches); matcher.match(query, matches);
assertListDMatchEquals(Arrays.asList(truth), matches, EPS); assertArrayDMatchEquals(truth, matches.toArray(), EPS);
} }
public void testMatchMatListOfDMatchListOfMat() { public void testMatchMatListOfDMatchListOfMat() {
Mat train = getTrainDescriptors(); Mat train = getTrainDescriptors();
Mat query = getQueryDescriptors(); Mat query = getQueryDescriptors();
Mat mask = getMaskImg(); Mat mask = getMaskImg();
List<DMatch> matches = new ArrayList<DMatch>(); MatOfDMatch matches = new MatOfDMatch();
matcher.add(Arrays.asList(train)); matcher.add(Arrays.asList(train));
matcher.train(); matcher.train();
matcher.match(query, matches, Arrays.asList(mask)); matcher.match(query, matches, Arrays.asList(mask));
assertListDMatchEquals(Arrays.asList(truth), matches, EPS); assertArrayDMatchEquals(truth, matches.toArray(), EPS);
} }
public void testMatchMatMatListOfDMatch() { public void testMatchMatMatListOfDMatch() {
Mat train = getTrainDescriptors(); Mat train = getTrainDescriptors();
Mat query = getQueryDescriptors(); Mat query = getQueryDescriptors();
List<DMatch> matches = new ArrayList<DMatch>(); MatOfDMatch matches = new MatOfDMatch();
matcher.match(query, train, matches); matcher.match(query, train, matches);
assertListDMatchEquals(Arrays.asList(truth), matches, EPS); assertArrayDMatchEquals(truth, matches.toArray(), EPS);
// OpenCVTestRunner.Log("matches found: " + matches.size()); // OpenCVTestRunner.Log("matches found: " + matches.size());
// for (DMatch m : matches) // for (DMatch m : matches)
...@@ -323,11 +324,11 @@ public class FlannBasedDescriptorMatcherTest extends OpenCVTestCase { ...@@ -323,11 +324,11 @@ public class FlannBasedDescriptorMatcherTest extends OpenCVTestCase {
Mat train = getTrainDescriptors(); Mat train = getTrainDescriptors();
Mat query = getQueryDescriptors(); Mat query = getQueryDescriptors();
Mat mask = getMaskImg(); Mat mask = getMaskImg();
List<DMatch> matches = new ArrayList<DMatch>(); MatOfDMatch matches = new MatOfDMatch();
matcher.match(query, train, matches, mask); matcher.match(query, train, matches, mask);
assertListDMatchEquals(Arrays.asList(truth), matches, EPS); assertListDMatchEquals(Arrays.asList(truth), matches.toList(), EPS);
} }
public void testRadiusMatchMatListOfListOfDMatchFloat() { public void testRadiusMatchMatListOfListOfDMatchFloat() {
...@@ -362,14 +363,15 @@ public class FlannBasedDescriptorMatcherTest extends OpenCVTestCase { ...@@ -362,14 +363,15 @@ public class FlannBasedDescriptorMatcherTest extends OpenCVTestCase {
Mat train = getBriefTrainDescriptors(); Mat train = getBriefTrainDescriptors();
Mat query = getBriefQueryDescriptors(); Mat query = getBriefQueryDescriptors();
List<DMatch> matches = new ArrayList<DMatch>(); MatOfDMatch matches = new MatOfDMatch();
matcher.match(query, train, matches); 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(1, 2, 0, 0),
new DMatch(2, 1, 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() { public void testTrain() {
......
...@@ -3,6 +3,7 @@ package org.opencv.test.features2d; ...@@ -3,6 +3,7 @@ package org.opencv.test.features2d;
import org.opencv.core.Core; import org.opencv.core.Core;
import org.opencv.core.CvType; import org.opencv.core.CvType;
import org.opencv.core.Mat; import org.opencv.core.Mat;
import org.opencv.core.MatOfKeyPoint;
import org.opencv.core.Point; import org.opencv.core.Point;
import org.opencv.core.Scalar; import org.opencv.core.Scalar;
import org.opencv.features2d.DescriptorExtractor; import org.opencv.features2d.DescriptorExtractor;
...@@ -10,9 +11,6 @@ import org.opencv.features2d.KeyPoint; ...@@ -10,9 +11,6 @@ import org.opencv.features2d.KeyPoint;
import org.opencv.test.OpenCVTestCase; import org.opencv.test.OpenCVTestCase;
import org.opencv.test.OpenCVTestRunner; import org.opencv.test.OpenCVTestRunner;
import java.util.Arrays;
import java.util.List;
public class ORBDescriptorExtractorTest extends OpenCVTestCase { public class ORBDescriptorExtractorTest extends OpenCVTestCase {
DescriptorExtractor extractor; DescriptorExtractor extractor;
...@@ -40,7 +38,7 @@ public class ORBDescriptorExtractorTest extends OpenCVTestCase { ...@@ -40,7 +38,7 @@ public class ORBDescriptorExtractorTest extends OpenCVTestCase {
public void testComputeMatListOfKeyPointMat() { public void testComputeMatListOfKeyPointMat() {
KeyPoint point = new KeyPoint(55.775577545166016f, 44.224422454833984f, 16, 9.754629f, 8617.863f, 1, -1); KeyPoint point = new KeyPoint(55.775577545166016f, 44.224422454833984f, 16, 9.754629f, 8617.863f, 1, -1);
List<KeyPoint> keypoints = Arrays.asList(point); MatOfKeyPoint keypoints = new MatOfKeyPoint(point);
Mat img = getTestImg(); Mat img = getTestImg();
Mat descriptors = new Mat(); Mat descriptors = new Mat();
...@@ -73,7 +71,7 @@ public class ORBDescriptorExtractorTest extends OpenCVTestCase { ...@@ -73,7 +71,7 @@ public class ORBDescriptorExtractorTest extends OpenCVTestCase {
public void testRead() { public void testRead() {
KeyPoint point = new KeyPoint(55.775577545166016f, 44.224422454833984f, 16, 9.754629f, 8617.863f, 1, -1); KeyPoint point = new KeyPoint(55.775577545166016f, 44.224422454833984f, 16, 9.754629f, 8617.863f, 1, -1);
List<KeyPoint> keypoints = Arrays.asList(point); MatOfKeyPoint keypoints = new MatOfKeyPoint(point);
Mat img = getTestImg(); Mat img = getTestImg();
Mat descriptors = new Mat(); Mat descriptors = new Mat();
......
...@@ -3,6 +3,7 @@ package org.opencv.test.features2d; ...@@ -3,6 +3,7 @@ package org.opencv.test.features2d;
import org.opencv.core.Core; import org.opencv.core.Core;
import org.opencv.core.CvType; import org.opencv.core.CvType;
import org.opencv.core.Mat; import org.opencv.core.Mat;
import org.opencv.core.MatOfKeyPoint;
import org.opencv.core.Point; import org.opencv.core.Point;
import org.opencv.core.Scalar; import org.opencv.core.Scalar;
import org.opencv.features2d.DescriptorExtractor; import org.opencv.features2d.DescriptorExtractor;
...@@ -10,9 +11,6 @@ import org.opencv.features2d.KeyPoint; ...@@ -10,9 +11,6 @@ import org.opencv.features2d.KeyPoint;
import org.opencv.test.OpenCVTestCase; import org.opencv.test.OpenCVTestCase;
import org.opencv.test.OpenCVTestRunner; import org.opencv.test.OpenCVTestRunner;
import java.util.Arrays;
import java.util.List;
public class SIFTDescriptorExtractorTest extends OpenCVTestCase { public class SIFTDescriptorExtractorTest extends OpenCVTestCase {
DescriptorExtractor extractor; DescriptorExtractor extractor;
...@@ -50,7 +48,7 @@ public class SIFTDescriptorExtractorTest extends OpenCVTestCase { ...@@ -50,7 +48,7 @@ public class SIFTDescriptorExtractorTest extends OpenCVTestCase {
} }
public void testComputeMatListOfKeyPointMat() { public void testComputeMatListOfKeyPointMat() {
List<KeyPoint> keypoints = Arrays.asList(keypoint); MatOfKeyPoint keypoints = new MatOfKeyPoint(keypoint);
Mat img = getTestImg(); Mat img = getTestImg();
Mat descriptors = new Mat(); Mat descriptors = new Mat();
...@@ -76,7 +74,7 @@ public class SIFTDescriptorExtractorTest extends OpenCVTestCase { ...@@ -76,7 +74,7 @@ public class SIFTDescriptorExtractorTest extends OpenCVTestCase {
} }
public void testRead() { public void testRead() {
List<KeyPoint> keypoints = Arrays.asList(keypoint); MatOfKeyPoint keypoints =new MatOfKeyPoint(keypoint);
Mat img = getTestImg(); Mat img = getTestImg();
Mat descriptors = new Mat(); Mat descriptors = new Mat();
......
package org.opencv.test.features2d; package org.opencv.test.features2d;
import java.util.Arrays;
import org.opencv.core.Core; import org.opencv.core.Core;
import org.opencv.core.CvType; import org.opencv.core.CvType;
import org.opencv.core.Mat; import org.opencv.core.Mat;
import org.opencv.core.MatOfKeyPoint;
import org.opencv.core.Point; import org.opencv.core.Point;
import org.opencv.core.Scalar; import org.opencv.core.Scalar;
import org.opencv.features2d.FeatureDetector; import org.opencv.features2d.FeatureDetector;
...@@ -10,10 +13,6 @@ import org.opencv.features2d.KeyPoint; ...@@ -10,10 +13,6 @@ import org.opencv.features2d.KeyPoint;
import org.opencv.test.OpenCVTestCase; import org.opencv.test.OpenCVTestCase;
import org.opencv.test.OpenCVTestRunner; import org.opencv.test.OpenCVTestRunner;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
public class STARFeatureDetectorTest extends OpenCVTestCase { public class STARFeatureDetectorTest extends OpenCVTestCase {
FeatureDetector detector; FeatureDetector detector;
...@@ -75,21 +74,21 @@ public class STARFeatureDetectorTest extends OpenCVTestCase { ...@@ -75,21 +74,21 @@ public class STARFeatureDetectorTest extends OpenCVTestCase {
public void testDetectMatListOfKeyPoint() { public void testDetectMatListOfKeyPoint() {
Mat img = getTestImg(); Mat img = getTestImg();
List<KeyPoint> keypoints = new ArrayList<KeyPoint>(); MatOfKeyPoint keypoints = new MatOfKeyPoint();
detector.detect(img, keypoints); detector.detect(img, keypoints);
assertListKeyPointEquals(Arrays.asList(truth), keypoints, EPS); assertListKeyPointEquals(Arrays.asList(truth), keypoints.toList(), EPS);
} }
public void testDetectMatListOfKeyPointMat() { public void testDetectMatListOfKeyPointMat() {
Mat img = getTestImg(); Mat img = getTestImg();
Mat mask = getMaskImg(); Mat mask = getMaskImg();
List<KeyPoint> keypoints = new ArrayList<KeyPoint>(); MatOfKeyPoint keypoints = new MatOfKeyPoint();
detector.detect(img, keypoints, mask); 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() { public void testEmpty() {
...@@ -99,17 +98,17 @@ public class STARFeatureDetectorTest extends OpenCVTestCase { ...@@ -99,17 +98,17 @@ public class STARFeatureDetectorTest extends OpenCVTestCase {
public void testRead() { public void testRead() {
Mat img = getTestImg(); Mat img = getTestImg();
List<KeyPoint> keypoints1 = new ArrayList<KeyPoint>(); MatOfKeyPoint keypoints1 = new MatOfKeyPoint();
detector.detect(img, keypoints1); detector.detect(img, keypoints1);
String filename = OpenCVTestRunner.getTempFileName("yml"); String filename = OpenCVTestRunner.getTempFileName("yml");
writeFile(filename, "%YAML:1.0\nmaxSize: 45\nresponseThreshold: 150\nlineThresholdProjected: 10\nlineThresholdBinarized: 8\nsuppressNonmaxSize: 5\n"); writeFile(filename, "%YAML:1.0\nmaxSize: 45\nresponseThreshold: 150\nlineThresholdProjected: 10\nlineThresholdBinarized: 8\nsuppressNonmaxSize: 5\n");
detector.read(filename); detector.read(filename);
List<KeyPoint> keypoints2 = new ArrayList<KeyPoint>(); MatOfKeyPoint keypoints2 = new MatOfKeyPoint();
detector.detect(img, keypoints2); detector.detect(img, keypoints2);
assertTrue(keypoints2.size() <= keypoints1.size()); assertTrue(keypoints2.total() <= keypoints1.total());
} }
public void testWrite() { public void testWrite() {
......
...@@ -3,6 +3,7 @@ package org.opencv.test.features2d; ...@@ -3,6 +3,7 @@ package org.opencv.test.features2d;
import org.opencv.core.Core; import org.opencv.core.Core;
import org.opencv.core.CvType; import org.opencv.core.CvType;
import org.opencv.core.Mat; import org.opencv.core.Mat;
import org.opencv.core.MatOfKeyPoint;
import org.opencv.core.Point; import org.opencv.core.Point;
import org.opencv.core.Scalar; import org.opencv.core.Scalar;
import org.opencv.features2d.DescriptorExtractor; import org.opencv.features2d.DescriptorExtractor;
...@@ -10,9 +11,6 @@ import org.opencv.features2d.KeyPoint; ...@@ -10,9 +11,6 @@ import org.opencv.features2d.KeyPoint;
import org.opencv.test.OpenCVTestCase; import org.opencv.test.OpenCVTestCase;
import org.opencv.test.OpenCVTestRunner; import org.opencv.test.OpenCVTestRunner;
import java.util.Arrays;
import java.util.List;
public class SURFDescriptorExtractorTest extends OpenCVTestCase { public class SURFDescriptorExtractorTest extends OpenCVTestCase {
DescriptorExtractor extractor; DescriptorExtractor extractor;
...@@ -40,7 +38,7 @@ public class SURFDescriptorExtractorTest extends OpenCVTestCase { ...@@ -40,7 +38,7 @@ public class SURFDescriptorExtractorTest extends OpenCVTestCase {
public void testComputeMatListOfKeyPointMat() { public void testComputeMatListOfKeyPointMat() {
KeyPoint point = new KeyPoint(55.775577545166016f, 44.224422454833984f, 16, 9.754629f, 8617.863f, 1, -1); KeyPoint point = new KeyPoint(55.775577545166016f, 44.224422454833984f, 16, 9.754629f, 8617.863f, 1, -1);
List<KeyPoint> keypoints = Arrays.asList(point); MatOfKeyPoint keypoints = new MatOfKeyPoint(point);
Mat img = getTestImg(); Mat img = getTestImg();
Mat descriptors = new Mat(); Mat descriptors = new Mat();
......
package org.opencv.test.features2d; 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.Core; import org.opencv.core.Core;
import org.opencv.core.CvType; import org.opencv.core.CvType;
import org.opencv.core.Mat; import org.opencv.core.Mat;
import org.opencv.core.MatOfKeyPoint;
import org.opencv.core.Point; import org.opencv.core.Point;
import org.opencv.core.Scalar; import org.opencv.core.Scalar;
import org.opencv.features2d.FeatureDetector; import org.opencv.features2d.FeatureDetector;
...@@ -10,12 +17,6 @@ import org.opencv.features2d.KeyPoint; ...@@ -10,12 +17,6 @@ import org.opencv.features2d.KeyPoint;
import org.opencv.test.OpenCVTestCase; import org.opencv.test.OpenCVTestCase;
import org.opencv.test.OpenCVTestRunner; 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;
public class SURFFeatureDetectorTest extends OpenCVTestCase { public class SURFFeatureDetectorTest extends OpenCVTestCase {
FeatureDetector detector; FeatureDetector detector;
...@@ -72,7 +73,7 @@ public class SURFFeatureDetectorTest extends OpenCVTestCase { ...@@ -72,7 +73,7 @@ public class SURFFeatureDetectorTest extends OpenCVTestCase {
writeFile(filename, "%YAML:1.0\nhessianThreshold: 8000.\noctaves: 3\noctaveLayers: 4\nupright: 0\n"); writeFile(filename, "%YAML:1.0\nhessianThreshold: 8000.\noctaves: 3\noctaveLayers: 4\nupright: 0\n");
detector.read(filename); detector.read(filename);
List<List<KeyPoint>> keypoints = new ArrayList<List<KeyPoint>>(); List<MatOfKeyPoint> keypoints = new ArrayList<MatOfKeyPoint>();
Mat cross = getTestImg(); Mat cross = getTestImg();
List<Mat> crosses = new ArrayList<Mat>(3); List<Mat> crosses = new ArrayList<Mat>(3);
crosses.add(cross); crosses.add(cross);
...@@ -83,7 +84,8 @@ public class SURFFeatureDetectorTest extends OpenCVTestCase { ...@@ -83,7 +84,8 @@ public class SURFFeatureDetectorTest extends OpenCVTestCase {
assertEquals(3, keypoints.size()); assertEquals(3, keypoints.size());
for (List<KeyPoint> lkp : keypoints) { for (MatOfKeyPoint mkp : keypoints) {
List<KeyPoint> lkp = mkp.toList();
order(lkp); order(lkp);
assertListKeyPointEquals(Arrays.asList(truth), lkp, EPS); assertListKeyPointEquals(Arrays.asList(truth), lkp, EPS);
} }
...@@ -98,13 +100,14 @@ public class SURFFeatureDetectorTest extends OpenCVTestCase { ...@@ -98,13 +100,14 @@ public class SURFFeatureDetectorTest extends OpenCVTestCase {
writeFile(filename, "%YAML:1.0\nhessianThreshold: 8000.\noctaves: 3\noctaveLayers: 4\nupright: 0\n"); writeFile(filename, "%YAML:1.0\nhessianThreshold: 8000.\noctaves: 3\noctaveLayers: 4\nupright: 0\n");
detector.read(filename); detector.read(filename);
List<KeyPoint> keypoints = new ArrayList<KeyPoint>(); MatOfKeyPoint keypoints = new MatOfKeyPoint();
Mat cross = getTestImg(); Mat cross = getTestImg();
detector.detect(cross, keypoints); detector.detect(cross, keypoints);
order(keypoints); List<KeyPoint> lkp = keypoints.toList();
assertListKeyPointEquals(Arrays.asList(truth), keypoints, EPS); order(lkp);
assertListKeyPointEquals(Arrays.asList(truth), lkp, EPS);
} }
public void testDetectMatListOfKeyPointMat() { public void testDetectMatListOfKeyPointMat() {
...@@ -114,12 +117,13 @@ public class SURFFeatureDetectorTest extends OpenCVTestCase { ...@@ -114,12 +117,13 @@ public class SURFFeatureDetectorTest extends OpenCVTestCase {
Mat img = getTestImg(); Mat img = getTestImg();
Mat mask = getMaskImg(); Mat mask = getMaskImg();
List<KeyPoint> keypoints = new ArrayList<KeyPoint>(); MatOfKeyPoint keypoints = new MatOfKeyPoint();
detector.detect(img, keypoints, mask); detector.detect(img, keypoints, mask);
order(keypoints); List<KeyPoint> lkp = keypoints.toList();
assertListKeyPointEquals(Arrays.asList(truth[1], truth[2]), keypoints, EPS); order(lkp);
assertListKeyPointEquals(Arrays.asList(truth[1], truth[2]), lkp, EPS);
} }
public void testEmpty() { public void testEmpty() {
...@@ -129,17 +133,17 @@ public class SURFFeatureDetectorTest extends OpenCVTestCase { ...@@ -129,17 +133,17 @@ public class SURFFeatureDetectorTest extends OpenCVTestCase {
public void testRead() { public void testRead() {
Mat cross = getTestImg(); Mat cross = getTestImg();
List<KeyPoint> keypoints1 = new ArrayList<KeyPoint>(); MatOfKeyPoint keypoints1 = new MatOfKeyPoint();
detector.detect(cross, keypoints1); detector.detect(cross, keypoints1);
String filename = OpenCVTestRunner.getTempFileName("yml"); String filename = OpenCVTestRunner.getTempFileName("yml");
writeFile(filename, "%YAML:1.0\nhessianThreshold: 8000.\noctaves: 3\noctaveLayers: 4\nupright: 0\n"); writeFile(filename, "%YAML:1.0\nhessianThreshold: 8000.\noctaves: 3\noctaveLayers: 4\nupright: 0\n");
detector.read(filename); detector.read(filename);
List<KeyPoint> keypoints2 = new ArrayList<KeyPoint>(); MatOfKeyPoint keypoints2 = new MatOfKeyPoint();
detector.detect(cross, keypoints2); detector.detect(cross, keypoints2);
assertTrue(keypoints2.size() <= keypoints1.size()); assertTrue(keypoints2.total() <= keypoints1.total());
} }
public void testWrite() { public void testWrite() {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment