diff --git a/modules/stitching/autocalib.cpp b/modules/stitching/autocalib.cpp index c6cd71212..de1c5efee 100644 --- a/modules/stitching/autocalib.cpp +++ b/modules/stitching/autocalib.cpp @@ -110,7 +110,7 @@ void estimateFocal(const vector &features, const vector &corners, const vector const vector &masks) { const int num_images = static_cast(images.size()); - Mat_ N(num_images, num_images); N.setTo(0); + Mat_ N(num_images, num_images); N.setTo(0); Mat_ I(num_images, num_images); I.setTo(0); Rect dst_roi = resultRoi(corners, images); @@ -99,8 +99,8 @@ void OverlapExposureCompensator::feed(const vector &corners, const vector } } } - I(i, j) = Isum1 / N(i, j); - I(j, i) = Isum2 / N(i, j); + I(i, j) = Isum1 / max(N(i, j), 1); + I(j, i) = Isum2 / max(N(i, j), 1); } } } diff --git a/modules/stitching/main.cpp b/modules/stitching/main.cpp index 3856c8d5a..9ed74c72e 100644 --- a/modules/stitching/main.cpp +++ b/modules/stitching/main.cpp @@ -341,8 +341,13 @@ int main(int argc, char* argv[]) vector img_subset; vector img_names_subset; for (size_t i = 0; i < indices.size(); ++i) + { img_names_subset.push_back(img_names[indices[i]]); + img_subset.push_back(images[indices[i]]); + } + img_names = img_names_subset; + images = img_subset; // Check if we still have enough images num_images = static_cast(img_names.size()); @@ -393,7 +398,7 @@ int main(int argc, char* argv[]) LOGLN("Camera #" << i << " focal length: " << cameras[i].focal); focals.push_back(cameras[i].focal); } - nth_element(focals.begin(), focals.end(), focals.begin() + focals.size() / 2); + nth_element(focals.begin(), focals.begin() + focals.size()/2, focals.end()); float warped_image_scale = static_cast(focals[focals.size() / 2]); LOGLN("Warping images (auxiliary)... "); diff --git a/modules/stitching/matchers.cpp b/modules/stitching/matchers.cpp index 2a396c9e4..69088c104 100644 --- a/modules/stitching/matchers.cpp +++ b/modules/stitching/matchers.cpp @@ -265,7 +265,7 @@ void FeaturesMatcher::operator ()(const vector &features, vector< // Leave k-nearest images int k = min(4, num_images); - nth_element(dists.begin(), dists.end(), dists.begin() + k); + nth_element(dists.begin(), dists.begin() + k, dists.end()); for (int j = 0; j < k; ++j) is_near(i, dists[j].idx) = 1; } @@ -273,7 +273,7 @@ void FeaturesMatcher::operator ()(const vector &features, vector< 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)) + if (is_near(i, j) || is_near(j, i)) near_pairs.push_back(make_pair(i, j)); pairwise_matches.resize(num_images * num_images);