minor refactoring of opencv_stitching
authorAlexey Spizhevoy <no@email>
Sat, 28 May 2011 13:03:28 +0000 (13:03 +0000)
committerAlexey Spizhevoy <no@email>
Sat, 28 May 2011 13:03:28 +0000 (13:03 +0000)
modules/stitching/main.cpp
modules/stitching/matchers.cpp
modules/stitching/motion_estimators.cpp

index df78f87..9d1a395 100644 (file)
@@ -79,7 +79,7 @@ void printUsage()
         "      Resolution for compositing step. Use -1 for original resolution.\n"\r
         "      The default is -1.\n"\r
         "  --match_conf <float>\n"\r
-        "      Confidence for feature matching step. The default is 0.6.\n"\r
+        "      Confidence for feature matching step. The default is 0.7.\n"\r
         "  --ba (ray|focal_ray)\n"\r
         "      Bundle adjustment cost function. The default is 'focal_ray'.\n"\r
         "  --conf_thresh <float>\n"\r
@@ -113,8 +113,7 @@ float conf_thresh = 1.f;
 bool wave_correct = true;\r
 int warp_type = Warper::SPHERICAL;\r
 int expos_comp_type = ExposureCompensator::GAIN;\r
-bool user_match_conf = false;\r
-float match_conf = 0.6f;\r
+float match_conf = 0.7f;\r
 int seam_find_type = SeamFinder::GC_COLOR;\r
 int blend_type = Blender::MULTI_BAND;\r
 int num_bands = 5;\r
@@ -129,7 +128,12 @@ int parseCmdArgs(int argc, char** argv)
     }\r
     for (int i = 1; i < argc; ++i)\r
     {\r
-        if (string(argv[i]) == "--preview")\r
+        if (string(argv[i]) == "--help" || string(argv[i]) == "/?")\r
+        {\r
+            printUsage();\r
+            return -1;\r
+        }\r
+        else if (string(argv[i]) == "--preview")\r
         {\r
             preview = true;\r
         }\r
@@ -168,7 +172,6 @@ int parseCmdArgs(int argc, char** argv)
         }\r
         else if (string(argv[i]) == "--match_conf")\r
         {\r
-            user_match_conf = true;\r
             match_conf = static_cast<float>(atof(argv[i + 1]));\r
             i++;\r
         }\r
@@ -348,7 +351,7 @@ int main(int argc, char* argv[])
 \r
         finder(img, features[i]);\r
         features[i].img_idx = i;\r
-        LOGLN("Features in image #" << i << ": " << features[i].keypoints.size());\r
+        LOGLN("Features in image #" << i+1 << ": " << features[i].keypoints.size());\r
 \r
         resize(full_img, img, Size(), seam_scale, seam_scale);\r
         images[i] = img.clone();\r
@@ -359,12 +362,10 @@ int main(int argc, char* argv[])
 \r
     LOGLN("Finding features, time: " << ((getTickCount() - t) / getTickFrequency()) << " sec");\r
 \r
-    LOGLN("Pairwise matching... ");\r
+    LOG("Pairwise matching");\r
     t = getTickCount();\r
     vector<MatchesInfo> pairwise_matches;\r
-    BestOf2NearestMatcher matcher(try_gpu);\r
-    if (user_match_conf)\r
-        matcher = BestOf2NearestMatcher(try_gpu, match_conf);\r
+    BestOf2NearestMatcher matcher(try_gpu, match_conf);\r
     matcher(features, pairwise_matches);\r
     LOGLN("Pairwise matching, time: " << ((getTickCount() - t) / getTickFrequency()) << " sec");\r
 \r
@@ -401,15 +402,25 @@ int main(int argc, char* argv[])
         Mat R;\r
         cameras[i].R.convertTo(R, CV_32F);\r
         cameras[i].R = R;\r
-        LOGLN("Initial focal length #" << i << ": " << cameras[i].focal);\r
+        LOGLN("Initial focal length #" << indices[i]+1 << ": " << cameras[i].focal);\r
     }\r
 \r
-    LOGLN("Bundle adjustment... ");\r
+    LOG("Bundle adjustment");\r
     t = getTickCount();\r
     BundleAdjuster adjuster(ba_space, conf_thresh);\r
     adjuster(features, pairwise_matches, cameras);\r
     LOGLN("Bundle adjustment, time: " << ((getTickCount() - t) / getTickFrequency()) << " sec");\r
 \r
+    // Find median focal length\r
+    vector<double> focals;\r
+    for (size_t i = 0; i < cameras.size(); ++i)\r
+    {\r
+        LOGLN("Camera #" << indices[i]+1 << " focal length: " << cameras[i].focal);\r
+        focals.push_back(cameras[i].focal);\r
+    }\r
+    nth_element(focals.begin(), focals.begin() + focals.size()/2, focals.end());\r
+    float warped_image_scale = static_cast<float>(focals[focals.size() / 2]);\r
+\r
     if (wave_correct)\r
     {\r
         LOGLN("Wave correcting...");\r
@@ -423,16 +434,6 @@ int main(int argc, char* argv[])
         LOGLN("Wave correcting, time: " << ((getTickCount() - t) / getTickFrequency()) << " sec");\r
     }\r
 \r
-    // Find median focal length\r
-    vector<double> focals;\r
-    for (size_t i = 0; i < cameras.size(); ++i)\r
-    {\r
-        LOGLN("Camera #" << i << " focal length: " << cameras[i].focal);\r
-        focals.push_back(cameras[i].focal);\r
-    }\r
-    nth_element(focals.begin(), focals.begin() + focals.size()/2, focals.end());\r
-    float warped_image_scale = static_cast<float>(focals[focals.size() / 2]);\r
-\r
     LOGLN("Warping images (auxiliary)... ");\r
     t = getTickCount();\r
 \r
@@ -496,7 +497,7 @@ int main(int argc, char* argv[])
 \r
     for (int img_idx = 0; img_idx < num_images; ++img_idx)\r
     {\r
-        LOGLN("Compositing image #" << img_idx);\r
+        LOGLN("Compositing image #" << indices[img_idx]+1);\r
 \r
         // Read image and resize it if necessary\r
         full_img = imread(img_names[img_idx]);\r
index 9301306..3d0639e 100644 (file)
@@ -219,6 +219,7 @@ struct MatchPairsBody
             for (size_t j = 0; j < pairwise_matches[dual_pair_idx].matches.size(); ++j)
                 swap(pairwise_matches[dual_pair_idx].matches[j].queryIdx,
                      pairwise_matches[dual_pair_idx].matches[j].trainIdx);
+            LOG(".");
         }
     }
 
@@ -248,6 +249,7 @@ void FeaturesMatcher::operator ()(const vector<ImageFeatures> &features, vector<
         parallel_for(BlockedRange(0, static_cast<int>(near_pairs.size())), body);
     else
         body(BlockedRange(0, static_cast<int>(near_pairs.size())));
+    LOGLN("");
 }
 
 
index 8a7a084..86cac2d 100644 (file)
@@ -198,14 +198,15 @@ void BundleAdjuster::estimate(const vector<ImageFeatures> &features, const vecto
         if (_err)
         {
             calcError(err_);
-            LOGLN("Error: " << sqrt(err_.dot(err_)));
+            LOG(".");
             count++;
             CvMat matErr = err_;
             cvCopy( &matErr, _err );
         }
     }
+    LOGLN("");
     LOGLN("Bundle adjustment, final error: " << sqrt(err_.dot(err_)));
-    LOGLN("Bundle adjustment, iteration done: " << count);
+    LOGLN("Bundle adjustment, iterations done: " << count);
 
     // Obtain global motion
     for (int i = 0; i < num_images_; ++i)
@@ -432,7 +433,8 @@ vector<int> leaveBiggestComponent(vector<ImageFeatures> &features,  vector<Match
 
     LOG("Removed some images, because can't match them: (");
     LOG(indices_removed[0]);
-    for (size_t i = 1; i < indices_removed.size(); ++i) LOG(", " << indices_removed[i]);
+    for (size_t i = 1; i < indices_removed.size(); ++i) 
+        LOG(", " << indices_removed[i]+1);
     LOGLN(")");
 
     features = features_subset;