added --ba_thresh key into opencv_stitching CLI
authorAlexey Spizhevoy <no@email>
Fri, 6 May 2011 05:14:07 +0000 (05:14 +0000)
committerAlexey Spizhevoy <no@email>
Fri, 6 May 2011 05:14:07 +0000 (05:14 +0000)
modules/stitching/main.cpp
modules/stitching/motion_estimators.cpp
modules/stitching/motion_estimators.hpp

index 5f8fce3..9468edb 100644 (file)
@@ -15,6 +15,7 @@ void printUsage()
         << "Usage: opencv_stitching img1 img2 [...imgN]\n" \r
         << "\t[--matchconf <0.0-1.0>]\n"\r
         << "\t[--ba (ray|focal_ray)]\n"\r
+        << "\t[--ba_thresh <float>]\n"\r
         //<< "\t[--wavecorrect (no|yes)]\n"\r
         << "\t[--warp (plane|cylindrical|spherical)]\n" \r
         << "\t[--seam (no|voronoi|graphcut)]\n" \r
@@ -29,6 +30,7 @@ int main(int argc, char* argv[])
     vector<Mat> images;\r
     string result_name = "result.png";\r
     int ba_space = BundleAdjuster::RAY_SPACE;\r
+    float ba_thresh = 1.f;\r
     bool wave_correct = false;\r
     int warp_type = Warper::SPHERICAL;\r
     bool user_match_conf = false;\r
@@ -52,7 +54,7 @@ int main(int argc, char* argv[])
         else if (string(argv[i]) == "--matchconf")\r
         {\r
             user_match_conf = true;\r
-            match_conf = static_cast<float>(atof(string(argv[i + 1]).c_str()));\r
+            match_conf = static_cast<float>(atof(argv[i + 1]));\r
             i++;\r
         }\r
         else if (string(argv[i]) == "--ba")\r
@@ -68,6 +70,11 @@ int main(int argc, char* argv[])
             }\r
             i++;\r
         }\r
+        else if (string(argv[i]) == "--ba_thresh")\r
+        {\r
+            ba_thresh = static_cast<float>(atof(argv[i + 1]));\r
+            i++;\r
+        }\r
         //else if (string(argv[i]) == "--wavecorrect")\r
         //{\r
         //    if (string(argv[i + 1]) == "no")\r
@@ -176,7 +183,7 @@ int main(int argc, char* argv[])
     }\r
 \r
     LOGLN("Bundle adjustment...");\r
-    BundleAdjuster adjuster(ba_space);\r
+    BundleAdjuster adjuster(ba_space, ba_thresh);\r
     adjuster(images, features, pairwise_matches, cameras);\r
 \r
     if (wave_correct)\r
index 952077a..2d2f02d 100644 (file)
@@ -491,8 +491,17 @@ void BundleAdjuster::estimate(const vector<Mat> &images, const vector<ImageFeatu
 
     edges_.clear();
     for (int i = 0; i < num_images_ - 1; ++i)
+    {
         for (int j = i + 1; j < num_images_; ++j)
-            edges_.push_back(make_pair(i, j));
+        {
+            int pair_idx = i * num_images_ + j;\r
+            const MatchesInfo& mi = pairwise_matches_[pair_idx];\r
+            float ni = static_cast<float>(mi.num_inliers);\r
+            float nf = static_cast<float>(mi.matches.size());\r
+            if (ni / (8.f + 0.3f * nf) > dist_thresh_)\r
+                edges_.push_back(make_pair(i, j));
+        }
+    }
 
     total_num_matches_ = 0;
     for (size_t i = 0; i < edges_.size(); ++i)
@@ -528,7 +537,7 @@ void BundleAdjuster::estimate(const vector<Mat> &images, const vector<ImageFeatu
         if (_err)
         {
             calcError(err_);
-            //LOGLN("Error: " << sqrt(err_.dot(err_)));
+            LOGLN("Error: " << sqrt(err_.dot(err_)));
             count++;
             CvMat matErr = err_;
             cvCopy( &matErr, _err );
index 02d4023..ac58aaf 100644 (file)
@@ -125,7 +125,8 @@ class BundleAdjuster : public Estimator
 public:
     enum { RAY_SPACE, FOCAL_RAY_SPACE };
 
-    BundleAdjuster(int cost_space = FOCAL_RAY_SPACE) : cost_space_(cost_space) {}
+    BundleAdjuster(int cost_space = FOCAL_RAY_SPACE, float dist_thresh = 1.f) 
+        : cost_space_(cost_space), dist_thresh_(dist_thresh) {}
 
 private:
     void estimate(const std::vector<cv::Mat> &images, const std::vector<ImageFeatures> &features,
@@ -143,6 +144,7 @@ private:
     std::vector<std::pair<int,int> > edges_;
 
     int cost_space_;
+    float dist_thresh_;
     cv::Mat err_, err1_, err2_;
     cv::Mat J_;
 };