|
|
|
@ -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 = "<?xml version=\"1.0\"?>\n" |
|
|
|
@ -109,7 +110,7 @@ public class FlannBasedDescriptorMatcherTest extends OpenCVTestCase { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private Mat getBriefTestDescriptors(Mat img) { |
|
|
|
|
List<KeyPoint> keypoints = new ArrayList<KeyPoint>(); |
|
|
|
|
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<KeyPoint> keypoints = new ArrayList<KeyPoint>(); |
|
|
|
|
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<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(); |
|
|
|
|
|
|
|
|
|
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<DMatch> matches = new ArrayList<DMatch>(); |
|
|
|
|
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<DMatch> matches = new ArrayList<DMatch>(); |
|
|
|
|
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<DMatch> matches = new ArrayList<DMatch>(); |
|
|
|
|
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<DMatch> matches = new ArrayList<DMatch>(); |
|
|
|
|
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<DMatch> matches = new ArrayList<DMatch>(); |
|
|
|
|
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() { |
|
|
|
|