From 4ba6793568112c310c3a6cee1234d1646fbd2c54 Mon Sep 17 00:00:00 2001 From: Alexey Spizhevoy Date: Sat, 21 May 2011 14:03:06 +0000 Subject: [PATCH] updated poor pairs filtering in opencv_stitching --- modules/stitching/matchers.cpp | 31 ++++++++++++++++++++++++++++--- 1 file changed, 28 insertions(+), 3 deletions(-) diff --git a/modules/stitching/matchers.cpp b/modules/stitching/matchers.cpp index 5d7e350..8360830 100644 --- a/modules/stitching/matchers.cpp +++ b/modules/stitching/matchers.cpp @@ -144,6 +144,14 @@ const MatchesInfo& MatchesInfo::operator =(const MatchesInfo &other) ////////////////////////////////////////////////////////////////////////////// +struct DistIdxPair +{ + bool operator<(const DistIdxPair &other) const { return dist < other.dist; } + double dist; + int idx; +}; + + void FeaturesMatcher::operator ()(const vector &features, vector &pairwise_matches) { const int num_images = static_cast(features.size()); @@ -152,11 +160,28 @@ void FeaturesMatcher::operator ()(const vector &features, vector< for (int i = 0; i < num_images; ++i) { LOGLN("Processing image " << i << "... "); + + vector dists(num_images); + for (int j = 0; j < num_images; ++j) + { + dists[j].dist = 1 - compareHist(features[i].hist, features[j].hist, CV_COMP_INTERSECT) + / min(features[i].img_size.area(), features[j].img_size.area()); + dists[j].idx = j; + } + + vector is_near(num_images, false); + for (int j = 0; j < num_images; ++j) + if (dists[j].dist < 0.6) + is_near[dists[j].idx] = true; + + int k = min(4, num_images); + nth_element(dists.begin(), dists.end(), dists.begin() + k); + for (int j = 0; j < k; ++j) + is_near[dists[j].idx] = true; + for (int j = i + 1; j < num_images; ++j) { - // Save time by ignoring poor pairs - if (compareHist(features[i].hist, features[j].hist, CV_COMP_INTERSECT) - < min(features[i].img_size.area(), features[j].img_size.area()) * 0.4) + if (!is_near[j]) continue; int pair_idx = i * num_images + j; -- 2.7.4