From 24e5ff7ab6168d8710a8d35c7a15e3d6899a3cb1 Mon Sep 17 00:00:00 2001 From: Alexey Spizhevoy Date: Thu, 26 May 2011 05:42:00 +0000 Subject: [PATCH] minor changes in opencv_stitching --- modules/stitching/main.cpp | 3 ++- modules/stitching/matchers.cpp | 32 ++------------------------------ modules/stitching/matchers.hpp | 1 + 3 files changed, 5 insertions(+), 31 deletions(-) diff --git a/modules/stitching/main.cpp b/modules/stitching/main.cpp index 9ed74c72eb..fdc3557186 100644 --- a/modules/stitching/main.cpp +++ b/modules/stitching/main.cpp @@ -316,6 +316,7 @@ int main(int argc, char* argv[]) } finder(img, features[i]); + features[i].img_idx = i; LOGLN("Features in image #" << i << ": " << features[i].keypoints.size()); resize(full_img, img, Size(), seam_scale, seam_scale); @@ -346,8 +347,8 @@ int main(int argc, char* argv[]) img_subset.push_back(images[indices[i]]); } - img_names = img_names_subset; images = img_subset; + img_names = img_names_subset; // Check if we still have enough images num_images = static_cast(img_names.size()); diff --git a/modules/stitching/matchers.cpp b/modules/stitching/matchers.cpp index 69088c1046..27f7411102 100644 --- a/modules/stitching/matchers.cpp +++ b/modules/stitching/matchers.cpp @@ -244,37 +244,10 @@ void FeaturesMatcher::operator ()(const vector &features, vector< { const int num_images = static_cast(features.size()); - Mat_ is_near(num_images, num_images); - is_near.setTo(0); - - // Find good image pairs - for (int i = 0; i < num_images; ++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; - } - - // Leave near images - for (int j = 0; j < num_images; ++j) - if (dists[j].dist < 0.6) - is_near(i, dists[j].idx) = 1; - - // Leave k-nearest images - int k = min(4, num_images); - nth_element(dists.begin(), dists.begin() + k, dists.end()); - for (int j = 0; j < k; ++j) - is_near(i, dists[j].idx) = 1; - } - vector > near_pairs; for (int i = 0; i < num_images - 1; ++i) for (int j = i + 1; j < num_images; ++j) - if (is_near(i, j) || is_near(j, i)) - near_pairs.push_back(make_pair(i, j)); + near_pairs.push_back(make_pair(i, j)); pairwise_matches.resize(num_images * num_images); MatchPairsBody body(*this, features, pairwise_matches, near_pairs); @@ -312,8 +285,7 @@ namespace private: float match_conf_; - GpuMat descriptors1_; - GpuMat descriptors2_; + GpuMat descriptors1_, descriptors2_; GpuMat train_idx_, distance_, all_dist_; }; diff --git a/modules/stitching/matchers.hpp b/modules/stitching/matchers.hpp index f331d1e66c..9ad6558f7e 100644 --- a/modules/stitching/matchers.hpp +++ b/modules/stitching/matchers.hpp @@ -46,6 +46,7 @@ struct ImageFeatures { + int img_idx; cv::Size img_size; cv::Mat hist; std::vector keypoints;