Filtering MatOfDMatch

2k views Asked by At

Refer to http://docs.opencv.org/2.4.2/doc/tutorials/features2d/feature_flann_matcher/feature_flann_matcher.html

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);
  1. Can this be done without the ugly back and forth conversions to lists?
  2. I've tried doing this via JNI, but how do I transfer the MatOFDMatch from Java to C++ and back?
0

There are 0 answers