now BA in opencv_stitching uses only geometrically consistent matches
authorAlexey Spizhevoy <no@email>
Fri, 6 May 2011 07:14:36 +0000 (07:14 +0000)
committerAlexey Spizhevoy <no@email>
Fri, 6 May 2011 07:14:36 +0000 (07:14 +0000)
modules/stitching/main.cpp
modules/stitching/motion_estimators.cpp
modules/stitching/motion_estimators.hpp

index 6a23286..d37d10c 100644 (file)
@@ -35,7 +35,7 @@ int main(int argc, char* argv[])
     string result_name = "result.png";\r
     int ba_space = BundleAdjuster::FOCAL_RAY_SPACE;\r
     float ba_thresh = 1.f;\r
-    bool wave_correct = false;\r
+    bool wave_correct = true;\r
     int warp_type = Warper::SPHERICAL;\r
     bool user_match_conf = false;\r
     float match_conf = 0.55f;\r
index 0974e1a..3f057cc 100644 (file)
@@ -309,13 +309,12 @@ void BestOf2NearestMatcher::match(const Mat &img1, const ImageFeatures &features
     }
 
     // Find pair-wise motion
-    vector<uchar> 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<Mat> &images, const vector<ImageFeatu
 
     total_num_matches_ = 0;
     for (size_t i = 0; i < edges_.size(); ++i)
-        total_num_matches_ += static_cast<int>(pairwise_matches[edges_[i].first * num_images_ + edges_[i].second].matches.size());
+        total_num_matches_ += static_cast<int>(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;
index ac58aaf..5152b50 100644 (file)
@@ -44,6 +44,7 @@ struct MatchesInfo
 
     int src_img_idx, dst_img_idx; // Optional images indices
     std::vector<cv::DMatch> matches;
+    std::vector<uchar> inliers_mask;
     int num_inliers; // Number of geometrically consistent matches
     cv::Mat H; // Homography
 };