From c5357cc17c0149ec9190cbcaf7a2409a6b1c709c Mon Sep 17 00:00:00 2001 From: Alexey Spizhevoy Date: Fri, 30 Sep 2011 12:46:11 +0000 Subject: [PATCH] Added fix for removing too similar images into the stitching module --- modules/stitching/src/matchers.cpp | 14 +++++++------- modules/stitching/src/motion_estimators.cpp | 7 ++++--- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/modules/stitching/src/matchers.cpp b/modules/stitching/src/matchers.cpp index f37fb467b..a720c6a63 100644 --- a/modules/stitching/src/matchers.cpp +++ b/modules/stitching/src/matchers.cpp @@ -427,12 +427,6 @@ void BestOf2NearestMatcher::match(const ImageFeatures &features1, const ImageFea { (*impl_)(features1, features2, matches_info); - //Mat out; - //drawMatches(features1.img, features1.keypoints, features2.img, features2.keypoints, matches_info.matches, out); - //stringstream ss; - //ss << features1.img_idx << features2.img_idx << ".png"; - //imwrite(ss.str(), out); - // Check if it makes sense to find homography if (matches_info.matches.size() < static_cast(num_matches_thresh1_)) return; @@ -466,7 +460,13 @@ void BestOf2NearestMatcher::match(const ImageFeatures &features1, const ImageFea if (matches_info.inliers_mask[i]) matches_info.num_inliers++; - matches_info.confidence = matches_info.num_inliers / (8 + 0.3*matches_info.matches.size()); + // These coeffs are from paper M. Brown and D. Lowe. "Automatic Panoramic Image Stitching + // using Invariant Features" + matches_info.confidence = matches_info.num_inliers / (8 + 0.3 * matches_info.matches.size()); + + // Set zero confidence to remove matches between too close images, as they don't provide + // additional information anyway. The threshold was set experimentally. + matches_info.confidence = matches_info.confidence > 3. ? 0. : matches_info.confidence; // Check if we should try to refine motion if (matches_info.num_inliers < num_matches_thresh2_) diff --git a/modules/stitching/src/motion_estimators.cpp b/modules/stitching/src/motion_estimators.cpp index 74ff57954..e8ebd1a6d 100644 --- a/modules/stitching/src/motion_estimators.cpp +++ b/modules/stitching/src/motion_estimators.cpp @@ -748,11 +748,12 @@ vector leaveBiggestComponent(vector &features, vector(features_subset.size()) == num_images) return indices; - LOG("Removed some images, because can't match them: ("); - LOG(indices_removed[0]+1); + LOG("Removed some images, because can't match them or there are too similar images: ("); + LOG(indices_removed[0] + 1); for (size_t i = 1; i < indices_removed.size(); ++i) LOG(", " << indices_removed[i]+1); - LOGLN("). Try to decrease --match_conf value."); + LOGLN(")."); + LOGLN("Try to decrease --match_conf value and/or check if you're stitching duplicates."); features = features_subset; pairwise_matches = pairwise_matches_subset;