At some point in my code I invoke
myDescriptorMatcher.match(descriptors, result);
Now, if I want to filter the resulting matches, I believe I have 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 the ugly back and forth conversions to lists?
- I've tried doing this via JNI, but how do I transfer the MatOFDMatch from Java to C++ and back?