Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Why does the BestOf2NearestMatcher's result depend on the input image order?

I get different matcher results with the BestOf2NearestMatcher from the stitching module when I swap the attribute order of the image feature inputs:

detail::BestOf2NearestMatcher matcher(false, 0.2);


matcher(imgFeat1, imgFeat2, matchesInfo); // 1095 matches, 811 inliers
matcher(imgFeat2, imgFeat1, matchesInfo); // 1107 matches, 787 inliers

Looking at the code of modules/stitching/src/matchers.cpp, line 179, I can't see a reason for this:

// Find 1->2 matches
matcher.knnMatch(features1.descriptors, features2.descriptors, pair_matches, 2);
for (size_t i = 0; i < pair_matches.size(); ++i)
{
    if (pair_matches[i].size() < 2)
        continue;
    const DMatch& m0 = pair_matches[i][0];
    const DMatch& m1 = pair_matches[i][1];
    if (m0.distance < (1.f - match_conf_) * m1.distance)
    {
        matches_info.matches.push_back(m0);
        matches.insert(make_pair(m0.queryIdx, m0.trainIdx));
    }
}
LOG("\n1->2 matches: " << matches_info.matches.size() << endl);

// Find 2->1 matches
pair_matches.clear();
matcher.knnMatch(features2.descriptors, features1.descriptors, pair_matches, 2);
for (size_t i = 0; i < pair_matches.size(); ++i)
{
    if (pair_matches[i].size() < 2)
        continue;
    const DMatch& m0 = pair_matches[i][0];
    const DMatch& m1 = pair_matches[i][1];
    if (m0.distance < (1.f - match_conf_) * m1.distance)
        if (matches.find(make_pair(m0.trainIdx, m0.queryIdx)) == matches.end())
            matches_info.matches.push_back(DMatch(m0.trainIdx, m0.queryIdx, m0.distance));
}

It seems to me like it should make no difference, as 1->2 matches and 2->1 matches are both added to the match list. Can anyone tell me where the different results come from? In my opinion the input order should make no difference, so this might be a bug...

Why does the BestOf2NearestMatcher's result depend on the image features input image order?

I get different matcher results with the BestOf2NearestMatcher from the stitching module when I swap the attribute input order of the image feature inputs:features:

detail::BestOf2NearestMatcher matcher(false, 0.2);


matcher(imgFeat1, imgFeat2, matchesInfo); // 1095 matches, 811 inliers
matcher(imgFeat2, imgFeat1, matchesInfo); // 1107 matches, 787 inliers

Looking at the code of modules/stitching/src/matchers.cpp, line 179, I can't see a reason for this:

// Find 1->2 matches
matcher.knnMatch(features1.descriptors, features2.descriptors, pair_matches, 2);
for (size_t i = 0; i < pair_matches.size(); ++i)
{
    if (pair_matches[i].size() < 2)
        continue;
    const DMatch& m0 = pair_matches[i][0];
    const DMatch& m1 = pair_matches[i][1];
    if (m0.distance < (1.f - match_conf_) * m1.distance)
    {
        matches_info.matches.push_back(m0);
        matches.insert(make_pair(m0.queryIdx, m0.trainIdx));
    }
}
LOG("\n1->2 matches: " << matches_info.matches.size() << endl);

// Find 2->1 matches
pair_matches.clear();
matcher.knnMatch(features2.descriptors, features1.descriptors, pair_matches, 2);
for (size_t i = 0; i < pair_matches.size(); ++i)
{
    if (pair_matches[i].size() < 2)
        continue;
    const DMatch& m0 = pair_matches[i][0];
    const DMatch& m1 = pair_matches[i][1];
    if (m0.distance < (1.f - match_conf_) * m1.distance)
        if (matches.find(make_pair(m0.trainIdx, m0.queryIdx)) == matches.end())
            matches_info.matches.push_back(DMatch(m0.trainIdx, m0.queryIdx, m0.distance));
}

It seems to me like it should make no difference, as 1->2 matches and 2->1 matches are both added to the match list. Can anyone tell me where the different results come from? In my opinion the input order should make no difference, so this might be a bug...