diff --git a/glomap/controllers/global_mapper_test.cc b/glomap/controllers/global_mapper_test.cc index 044c917..b1a4062 100644 --- a/glomap/controllers/global_mapper_test.cc +++ b/glomap/controllers/global_mapper_test.cc @@ -40,13 +40,6 @@ void ExpectEqualReconstructions(const colmap::Reconstruction& gt, GlobalMapperOptions CreateTestOptions() { GlobalMapperOptions options; - // Control the verbosity of the global sfm - options.opt_vgcalib.verbose = false; - options.opt_ra.verbose = false; - options.opt_gp.verbose = false; - options.opt_ba.verbose = false; - - // Control the flow of the global sfm options.skip_view_graph_calibration = false; options.skip_relative_pose_estimation = false; options.skip_rotation_averaging = false; diff --git a/glomap/controllers/option_manager.cc b/glomap/controllers/option_manager.cc index 39c17f8..d1e0304 100644 --- a/glomap/controllers/option_manager.cc +++ b/glomap/controllers/option_manager.cc @@ -17,6 +17,9 @@ OptionManager::OptionManager(bool add_project_options) { Reset(); desc_->add_options()("help,h", ""); + + AddAndRegisterDefaultOption("log_to_stderr", &FLAGS_logtostderr); + AddAndRegisterDefaultOption("log_level", &FLAGS_v); } void OptionManager::AddAllOptions() { diff --git a/glomap/estimators/bundle_adjustment.cc b/glomap/estimators/bundle_adjustment.cc index a03bea5..32204ba 100644 --- a/glomap/estimators/bundle_adjustment.cc +++ b/glomap/estimators/bundle_adjustment.cc @@ -40,9 +40,9 @@ bool BundleAdjuster::Solve(const ViewGraph& view_graph, options_.solver_options.linear_solver_type = ceres::SPARSE_SCHUR; options_.solver_options.preconditioner_type = ceres::CLUSTER_TRIDIAGONAL; - options_.solver_options.minimizer_progress_to_stdout = options_.verbose; + options_.solver_options.minimizer_progress_to_stdout = VLOG_IS_ON(2); ceres::Solve(options_.solver_options, problem_.get(), &summary); - if (options_.verbose) + if (VLOG_IS_ON(2)) LOG(INFO) << summary.FullReport(); else LOG(INFO) << summary.BriefReport(); diff --git a/glomap/estimators/global_positioning.cc b/glomap/estimators/global_positioning.cc index 5590903..b18fa80 100644 --- a/glomap/estimators/global_positioning.cc +++ b/glomap/estimators/global_positioning.cc @@ -68,10 +68,10 @@ bool GlobalPositioner::Solve(const ViewGraph& view_graph, LOG(INFO) << "Solving the global positioner problem"; ceres::Solver::Summary summary; - options_.solver_options.minimizer_progress_to_stdout = options_.verbose; + options_.solver_options.minimizer_progress_to_stdout = VLOG_IS_ON(2); ceres::Solve(options_.solver_options, problem_.get(), &summary); - if (options_.verbose) { + if (VLOG_IS_ON(2)) { LOG(INFO) << summary.FullReport(); } else { LOG(INFO) << summary.BriefReport(); @@ -143,8 +143,7 @@ void GlobalPositioner::InitializeRandomPositions( image.cam_from_world.translation = image.Center(); } - if (options_.verbose) - LOG(INFO) << "Constrained positions: " << constrained_positions.size(); + VLOG(2) << "Constrained positions: " << constrained_positions.size(); } void GlobalPositioner::AddCameraToCameraConstraints( @@ -178,10 +177,9 @@ void GlobalPositioner::AddCameraToCameraConstraints( problem_->SetParameterLowerBound(&scale, 0, 1e-5); } - if (options_.verbose) - LOG(INFO) << problem_->NumResidualBlocks() - << " camera to camera constraints were added to the position " - "estimation problem."; + VLOG(2) << problem_->NumResidualBlocks() + << " camera to camera constraints were added to the position " + "estimation problem."; } void GlobalPositioner::AddPointToCameraConstraints( @@ -194,10 +192,9 @@ void GlobalPositioner::AddPointToCameraConstraints( // Find the tracks that are relevant to the current set of cameras const size_t num_pt_to_cam = tracks.size(); - if (options_.verbose) - LOG(INFO) << num_pt_to_cam - << " point to camera constriants were added to the position " - "estimation problem."; + VLOG(2) << num_pt_to_cam + << " point to camera constriants were added to the position " + "estimation problem."; if (num_pt_to_cam == 0) return; @@ -211,8 +208,7 @@ void GlobalPositioner::AddPointToCameraConstraints( static_cast(num_cam_to_cam) / static_cast(num_pt_to_cam); } - if (options_.verbose) - LOG(INFO) << "Point to camera weight scaled: " << weight_scale_pt; + VLOG(2) << "Point to camera weight scaled: " << weight_scale_pt; if (loss_function_ptcam_uncalibrated_ == nullptr) { loss_function_ptcam_uncalibrated_ = diff --git a/glomap/estimators/global_rotation_averaging.cc b/glomap/estimators/global_rotation_averaging.cc index 429a6bd..3f7d031 100644 --- a/glomap/estimators/global_rotation_averaging.cc +++ b/glomap/estimators/global_rotation_averaging.cc @@ -156,10 +156,6 @@ void RotationEstimator::SetupLinearSystem( } } - if (options_.verbose) - LOG(INFO) << "num_img: " << image_id_to_idx_.size() - << ", num_dof: " << num_dof; - rotation_estimated_.conservativeResize(num_dof); // Prepare the relative information @@ -204,8 +200,7 @@ void RotationEstimator::SetupLinearSystem( } } - if (options_.verbose) - LOG(INFO) << counter << " image pairs are gravity aligned" << std::endl; + VLOG(2) << counter << " image pairs are gravity aligned" << std::endl; std::vector> coeffs; coeffs.reserve(rel_temp_info_.size() * 6 + 3); @@ -290,11 +285,11 @@ bool RotationEstimator::SolveL1Regression( double curr_norm = 0; ComputeResiduals(view_graph, images); - if (options_.verbose) LOG(INFO) << "ComputeResiduals done "; + VLOG(2) << "ComputeResiduals done"; int iteration = 0; for (iteration = 0; iteration < options_.max_num_l1_iterations; iteration++) { - if (options_.verbose) LOG(INFO) << "L1 ADMM iteration: " << iteration; + VLOG(2) << "L1 ADMM iteration: " << iteration; last_norm = curr_norm; // use the current residual as b (Ax - b) @@ -307,7 +302,7 @@ bool RotationEstimator::SolveL1Regression( return false; } - if (options_.verbose) + if (VLOG_IS_ON(2)) LOG(INFO) << "residual:" << (sparse_matrix_ * tangent_space_step_ - tangent_space_residual_) @@ -332,7 +327,7 @@ bool RotationEstimator::SolveL1Regression( opt_l1_solver.max_num_iterations = std::min(opt_l1_solver.max_num_iterations * 2, 100); } - if (options_.verbose) LOG(INFO) << "L1 ADMM total iteration: " << iteration; + VLOG(2) << "L1 ADMM total iteration: " << iteration; return true; } @@ -347,8 +342,7 @@ bool RotationEstimator::SolveIRLS(const ViewGraph& view_graph, llt.analyzePattern(sparse_matrix_.transpose() * sparse_matrix_); const double sigma = DegToRad(options_.irls_loss_parameter_sigma); - if (options_.verbose) - LOG(INFO) << "sigma: " << options_.irls_loss_parameter_sigma; + VLOG(2) << "sigma: " << options_.irls_loss_parameter_sigma; Eigen::ArrayXd weights_irls(sparse_matrix_.rows()); Eigen::SparseMatrix at_weight; @@ -362,7 +356,7 @@ bool RotationEstimator::SolveIRLS(const ViewGraph& view_graph, int iteration = 0; for (iteration = 0; iteration < options_.max_num_irls_iterations; iteration++) { - if (options_.verbose) LOG(INFO) << "IRLS iteration: " << iteration; + VLOG(2) << "IRLS iteration: " << iteration; // Compute the weights for IRLS for (auto& [pair_id, pair_info] : rel_temp_info_) { @@ -416,7 +410,7 @@ bool RotationEstimator::SolveIRLS(const ViewGraph& view_graph, break; } } - if (options_.verbose) LOG(INFO) << "IRLS total iteration: " << iteration; + VLOG(2) << "IRLS total iteration: " << iteration; return true; } diff --git a/glomap/estimators/global_rotation_averaging.h b/glomap/estimators/global_rotation_averaging.h index 7b73d34..8899a1c 100644 --- a/glomap/estimators/global_rotation_averaging.h +++ b/glomap/estimators/global_rotation_averaging.h @@ -68,9 +68,6 @@ struct RotationEstimatorOptions { // Flag to use gravity for rotation averaging bool use_gravity = false; - - // Flag whether report the verbose information - bool verbose = false; }; // TODO: Implement the stratified camera rotation estimation diff --git a/glomap/estimators/optimization_base.h b/glomap/estimators/optimization_base.h index 6234ca2..2b43e06 100644 --- a/glomap/estimators/optimization_base.h +++ b/glomap/estimators/optimization_base.h @@ -9,9 +9,6 @@ namespace glomap { struct OptimizationBaseOptions { - // Logging control - bool verbose = false; - // The threshold for the loss function double thres_loss_function = 1e-1; @@ -24,7 +21,7 @@ struct OptimizationBaseOptions { OptimizationBaseOptions() { solver_options.num_threads = std::thread::hardware_concurrency(); solver_options.max_num_iterations = 100; - solver_options.minimizer_progress_to_stdout = verbose; + solver_options.minimizer_progress_to_stdout = false; solver_options.function_tolerance = 1e-5; } }; diff --git a/glomap/estimators/view_graph_calibration.cc b/glomap/estimators/view_graph_calibration.cc index 7991055..7d5b457 100644 --- a/glomap/estimators/view_graph_calibration.cc +++ b/glomap/estimators/view_graph_calibration.cc @@ -36,13 +36,10 @@ bool ViewGraphCalibrator::Solve(ViewGraph& view_graph, // Solve the problem ceres::Solver::Summary summary; - options_.solver_options.minimizer_progress_to_stdout = options_.verbose; + options_.solver_options.minimizer_progress_to_stdout = VLOG_IS_ON(2); ceres::Solve(options_.solver_options, problem_.get(), &summary); - // Print the summary only if verbose - if (options_.verbose) { - LOG(INFO) << summary.FullReport(); - } + VLOG(2) << summary.FullReport(); // Convert the results back to the camera CopyBackResults(cameras); @@ -132,10 +129,9 @@ void ViewGraphCalibrator::CopyBackResults( // if the estimated parameter is too crazy, reject it if (focals_[camera_id] / camera.Focal() > options_.thres_higher_ratio || focals_[camera_id] / camera.Focal() < options_.thres_lower_ratio) { - if (options_.verbose) - LOG(INFO) << "NOT ACCEPTED: Camera " << camera_id - << " focal: " << focals_[camera_id] - << " original focal: " << camera.Focal(); + VLOG(2) << "Ignoring degenerate camera camera " << camera_id + << " focal: " << focals_[camera_id] + << " original focal: " << camera.Focal(); counter++; continue; @@ -147,9 +143,6 @@ void ViewGraphCalibrator::CopyBackResults( // Update the focal length for (const size_t idx : camera.FocalLengthIdxs()) { camera.params[idx] = focals_[camera_id]; - if (options_.verbose) - LOG(INFO) << "Camera " << idx << " focal: " << focals_[camera_id] - << std::endl; } } LOG(INFO) << counter << " cameras are rejected in view graph calibration";