See http://docs.opencv.org/2.4.2/doc/tutorials/features2d/feature_flann_matcher/feature_flann_matcher.html
At some point in my code, I call
myDescriptorMatcher.match(descriptors, result);
Now, if I want to filter out the received matches, I believe that I need to do something ugly, like:
List<DMatch> matchesList = matches.toList(); double maxDistance = 0; double minDistance = 1000; int rowCount = matchesList.size(); for (int i = 0; i < rowCount; i++) { double dist = matchesList.get(i).distance; if (dist < minDistance) minDistance = dist; if (dist > maxDistance) maxDistance = dist; } List<DMatch> goodMatchesList = new ArrayList<DMatch>(); double upperBound = 6 * minDistance; for (int i = 0; i < rowCount; i++) { if (matchesList.get(i).distance < upperBound) { goodMatchesList.add(matchesList.get(i)); } } MatOfDMatch goodMatches = new MatOfDMatch(); goodMatches.fromList(goodMatchesList); Features2d.drawMatches(mPreviousGray.submat(roi), mPrevDetectedFeatures, m.submat(roi), curDetectedFeatures, goodMatches, result);
- Can this be done without ugly transitions back and forth to the lists?
- I tried to do this through JNI, but how to pass MatOFDMatch from Java to C ++ and vice versa?
source share