diff --git a/modules/stitching/main.cpp b/modules/stitching/main.cpp index 6a2328616..d37d10c54 100644 --- a/modules/stitching/main.cpp +++ b/modules/stitching/main.cpp @@ -35,7 +35,7 @@ int main(int argc, char* argv[]) string result_name = "result.png"; int ba_space = BundleAdjuster::FOCAL_RAY_SPACE; float ba_thresh = 1.f; - bool wave_correct = false; + bool wave_correct = true; int warp_type = Warper::SPHERICAL; bool user_match_conf = false; float match_conf = 0.55f; diff --git a/modules/stitching/motion_estimators.cpp b/modules/stitching/motion_estimators.cpp index 0974e1ad2..3f057ccdf 100644 --- a/modules/stitching/motion_estimators.cpp +++ b/modules/stitching/motion_estimators.cpp @@ -309,13 +309,12 @@ void BestOf2NearestMatcher::match(const Mat &img1, const ImageFeatures &features } // Find pair-wise motion - vector inlier_mask; - matches_info.H = findHomography(src_points, dst_points, inlier_mask, CV_RANSAC); + matches_info.H = findHomography(src_points, dst_points, matches_info.inliers_mask, CV_RANSAC); // Find number of inliers matches_info.num_inliers = 0; - for (size_t i = 0; i < inlier_mask.size(); ++i) - if (inlier_mask[i]) + for (size_t i = 0; i < matches_info.inliers_mask.size(); ++i) + if (matches_info.inliers_mask[i]) matches_info.num_inliers++; // Check if we should try to refine motion @@ -328,8 +327,9 @@ void BestOf2NearestMatcher::match(const Mat &img1, const ImageFeatures &features int inlier_idx = 0; for (size_t i = 0; i < matches_info.matches.size(); ++i) { - if (!inlier_mask[i]) + if (!matches_info.inliers_mask[i]) continue; + const DMatch& m = matches_info.matches[i]; Point2f p = features1.keypoints[m.queryIdx].pt; @@ -346,13 +346,7 @@ void BestOf2NearestMatcher::match(const Mat &img1, const ImageFeatures &features } // Rerun motion estimation on inliers only - matches_info.H = findHomography(src_points, dst_points, inlier_mask, CV_RANSAC); - - // Find number of inliers - matches_info.num_inliers = 0; - for (size_t i = 0; i < inlier_mask.size(); ++i) - if (inlier_mask[i]) - matches_info.num_inliers++; + matches_info.H = findHomography(src_points, dst_points, CV_RANSAC); } @@ -505,7 +499,7 @@ void BundleAdjuster::estimate(const vector &images, const vector(pairwise_matches[edges_[i].first * num_images_ + edges_[i].second].matches.size()); + total_num_matches_ += static_cast(pairwise_matches[edges_[i].first * num_images_ + edges_[i].second].num_inliers); CvLevMarq solver(num_images_ * 4, total_num_matches_ * 3, cvTermCriteria(CV_TERMCRIT_EPS + CV_TERMCRIT_ITER, 100, DBL_EPSILON)); @@ -599,6 +593,9 @@ void BundleAdjuster::calcError(Mat &err) for (size_t k = 0; k < matches_info.matches.size(); ++k) { + if (!matches_info.inliers_mask[k]) + continue; + const DMatch& m = matches_info.matches[k]; Point2d kp1 = features1.keypoints[m.queryIdx].pt; diff --git a/modules/stitching/motion_estimators.hpp b/modules/stitching/motion_estimators.hpp index ac58aafc9..5152b504c 100644 --- a/modules/stitching/motion_estimators.hpp +++ b/modules/stitching/motion_estimators.hpp @@ -44,6 +44,7 @@ struct MatchesInfo int src_img_idx, dst_img_idx; // Optional images indices std::vector matches; + std::vector inliers_mask; int num_inliers; // Number of geometrically consistent matches cv::Mat H; // Homography };