Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions src/colmap/controllers/incremental_pipeline.cc
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,13 @@ BundleAdjustmentOptions IncrementalPipelineOptions::LocalBundleAdjustment()
options.refine_principal_point = ba_refine_principal_point;
options.refine_extra_params = ba_refine_extra_params;
options.refine_sensor_from_rig = ba_refine_sensor_from_rig;
options.focal_length_prior_weight = ba_focal_length_prior_weight;
options.principal_point_prior_weight = ba_principal_point_prior_weight;
options.extra_params_prior_weight = ba_extra_params_prior_weight;
options.bound_camera_params = ba_bound_camera_params;
options.min_focal_length_ratio = min_focal_length_ratio;
options.max_focal_length_ratio = max_focal_length_ratio;
options.max_extra_param = max_extra_param;
if (options.ceres) {
options.ceres->solver_options.function_tolerance =
ba_local_function_tolerance;
Expand Down Expand Up @@ -219,6 +226,13 @@ BundleAdjustmentOptions IncrementalPipelineOptions::GlobalBundleAdjustment()
options.refine_principal_point = ba_refine_principal_point;
options.refine_extra_params = ba_refine_extra_params;
options.refine_sensor_from_rig = ba_refine_sensor_from_rig;
options.focal_length_prior_weight = ba_focal_length_prior_weight;
options.principal_point_prior_weight = ba_principal_point_prior_weight;
options.extra_params_prior_weight = ba_extra_params_prior_weight;
options.bound_camera_params = ba_bound_camera_params;
options.min_focal_length_ratio = min_focal_length_ratio;
options.max_focal_length_ratio = max_focal_length_ratio;
options.max_extra_param = max_extra_param;
if (options.ceres) {
options.ceres->solver_options.function_tolerance =
ba_global_function_tolerance;
Expand Down Expand Up @@ -286,6 +300,9 @@ bool IncrementalPipelineOptions::Check() const {
CHECK_OPTION_GT(min_focal_length_ratio, 0);
CHECK_OPTION_GT(max_focal_length_ratio, 0);
CHECK_OPTION_GE(max_extra_param, 0);
CHECK_OPTION_GE(ba_focal_length_prior_weight, 0);
CHECK_OPTION_GE(ba_principal_point_prior_weight, 0);
CHECK_OPTION_GE(ba_extra_params_prior_weight, 0);
CHECK_OPTION_GE(ba_local_max_num_iterations, -1);
CHECK_OPTION_GT(ba_global_frames_ratio, 1.0);
CHECK_OPTION_GT(ba_global_points_ratio, 1.0);
Expand Down
12 changes: 12 additions & 0 deletions src/colmap/controllers/incremental_pipeline.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,18 @@ struct IncrementalPipelineOptions {
bool ba_refine_principal_point = false;
bool ba_refine_extra_params = true;

// Weights for soft priors on the camera intrinsics during bundle
// adjustment. A weight of 0 disables the respective prior. See
// BundleAdjustmentOptions for details.
double ba_focal_length_prior_weight = 0;
double ba_principal_point_prior_weight = 0;
double ba_extra_params_prior_weight = 0;

// Whether to constrain the camera intrinsics during bundle adjustment to
// the same bounds that the degenerate intrinsics filter above applies. See
// BundleAdjustmentOptions::bound_camera_params.
bool ba_bound_camera_params = false;

// Whether to optimize rig poses during the reconstruction.
bool ba_refine_sensor_from_rig = true;

Expand Down
42 changes: 42 additions & 0 deletions src/colmap/controllers/option_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -577,6 +577,20 @@ void OptionManager::AddBundleAdjustmentOptions() {
&bundle_adjustment->constant_rig_from_world_rotation);
AddDefaultOption("BundleAdjustment.min_track_length",
&bundle_adjustment->min_track_length);
AddDefaultOption("BundleAdjustment.focal_length_prior_weight",
&bundle_adjustment->focal_length_prior_weight);
AddDefaultOption("BundleAdjustment.principal_point_prior_weight",
&bundle_adjustment->principal_point_prior_weight);
AddDefaultOption("BundleAdjustment.extra_params_prior_weight",
&bundle_adjustment->extra_params_prior_weight);
AddDefaultOption("BundleAdjustment.bound_camera_params",
&bundle_adjustment->bound_camera_params);
AddDefaultOption("BundleAdjustment.min_focal_length_ratio",
&bundle_adjustment->min_focal_length_ratio);
AddDefaultOption("BundleAdjustment.max_focal_length_ratio",
&bundle_adjustment->max_focal_length_ratio);
AddDefaultOption("BundleAdjustment.max_extra_param",
&bundle_adjustment->max_extra_param);
AddDefaultEnumOption("BundleAdjustment.backend",
&bundle_adjustment->backend,
BundleAdjustmentBackendToString,
Expand Down Expand Up @@ -686,6 +700,14 @@ void OptionManager::AddMapperOptions() {
&mapper->ba_refine_extra_params);
AddDefaultOption("Mapper.ba_refine_sensor_from_rig",
&mapper->ba_refine_sensor_from_rig);
AddDefaultOption("Mapper.ba_focal_length_prior_weight",
&mapper->ba_focal_length_prior_weight);
AddDefaultOption("Mapper.ba_principal_point_prior_weight",
&mapper->ba_principal_point_prior_weight);
AddDefaultOption("Mapper.ba_extra_params_prior_weight",
&mapper->ba_extra_params_prior_weight);
AddDefaultOption("Mapper.ba_bound_camera_params",
&mapper->ba_bound_camera_params);
AddDefaultOption("Mapper.ba_local_function_tolerance",
&mapper->ba_local_function_tolerance);
AddDefaultOption("Mapper.ba_local_max_num_iterations",
Expand Down Expand Up @@ -875,6 +897,26 @@ void OptionManager::AddGlobalMapperOptions() {
&global_mapper->mapper.bundle_adjustment.refine_points3D);
AddDefaultOption("GlobalMapper.ba_min_track_length",
&global_mapper->mapper.bundle_adjustment.min_track_length);
AddDefaultOption(
"GlobalMapper.ba_focal_length_prior_weight",
&global_mapper->mapper.bundle_adjustment.focal_length_prior_weight);
AddDefaultOption(
"GlobalMapper.ba_principal_point_prior_weight",
&global_mapper->mapper.bundle_adjustment.principal_point_prior_weight);
AddDefaultOption(
"GlobalMapper.ba_extra_params_prior_weight",
&global_mapper->mapper.bundle_adjustment.extra_params_prior_weight);
AddDefaultOption(
"GlobalMapper.ba_bound_camera_params",
&global_mapper->mapper.bundle_adjustment.bound_camera_params);
AddDefaultOption(
"GlobalMapper.ba_min_focal_length_ratio",
&global_mapper->mapper.bundle_adjustment.min_focal_length_ratio);
AddDefaultOption(
"GlobalMapper.ba_max_focal_length_ratio",
&global_mapper->mapper.bundle_adjustment.max_focal_length_ratio);
AddDefaultOption("GlobalMapper.ba_max_extra_param",
&global_mapper->mapper.bundle_adjustment.max_extra_param);
AddDefaultEnumOption("GlobalMapper.ba_backend",
&global_mapper->mapper.bundle_adjustment.backend,
BundleAdjustmentBackendToString,
Expand Down
16 changes: 16 additions & 0 deletions src/colmap/estimators/bundle_adjustment.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "colmap/estimators/bundle_adjustment_caspar.h"
#include "colmap/estimators/bundle_adjustment_ceres.h"
#include "colmap/util/hash_containers.h"
#include "colmap/util/logging.h"

namespace colmap {

Expand Down Expand Up @@ -281,6 +282,12 @@ BundleAdjustmentBackendOptions& BundleAdjustmentBackendOptions::operator=(
}

bool BundleAdjustmentOptions::Check() const {
CHECK_OPTION_GE(focal_length_prior_weight, 0);
CHECK_OPTION_GE(principal_point_prior_weight, 0);
CHECK_OPTION_GE(extra_params_prior_weight, 0);
CHECK_OPTION_GT(min_focal_length_ratio, 0);
CHECK_OPTION_GE(max_focal_length_ratio, min_focal_length_ratio);
CHECK_OPTION_GE(max_extra_param, 0);
return THROW_CHECK_NOTNULL(ceres)->Check();
}

Expand All @@ -293,6 +300,15 @@ std::unique_ptr<BundleAdjuster> CreateDefaultBundleAdjuster(
return CreateDefaultCeresBundleAdjuster(options, config, reconstruction);
case BundleAdjustmentBackend::CASPAR:
#ifdef CASPAR_ENABLED
if (options.focal_length_prior_weight > 0 ||
options.principal_point_prior_weight > 0 ||
options.extra_params_prior_weight > 0 ||
options.bound_camera_params) {
LOG_FIRST_N(WARNING, 1)
<< "Camera intrinsics priors and parameter bounds are not "
"supported by the Caspar bundle adjustment backend and are "
"ignored";
}
return CreateDefaultCasparBundleAdjuster(options, config, reconstruction);
#else
LOG(FATAL_THROW)
Expand Down
38 changes: 38 additions & 0 deletions src/colmap/estimators/bundle_adjustment.h
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,44 @@ struct BundleAdjustmentOptions : public BundleAdjustmentBackendOptions {
// Whether to print a final summary.
bool print_summary = true;

// Weights for soft priors on the camera intrinsics. Each weight is the
// inverse standard deviation of the assumed Gaussian prior, i.e.
// weight = 1 / stddev, so a weight of 0 means an infinite standard deviation
// and disables the respective prior.
//
// The focal length and principal point weights are direct multipliers on
// deviations in pixels. The extra parameter weight is multiplied by the mean
// focal length at the time the problem is constructed to convert
// dimensionless deviations to pixel-like residuals. Note that the effective
// strength of the extra parameter prior therefore depends on the field of
// view: at equal resolution, a small field-of-view camera is pulled towards
// its prior more strongly than a wide field-of-view one.
//
// The focal length prior is only applied to cameras with
// Camera::has_prior_focal_length and pulls towards the focal length at the
// time the problem is constructed. Thus "initial" means the construction-time
// value for each bundle adjustment problem, not necessarily the original
// database value. The prior therefore acts as a damping term across
// successive problems rather than as an anchor to the original prior, e.g.
// EXIF focal length. The principal point and extra parameter priors pull
// towards the values the camera model initializes them to, i.e. the image
// center and, for most models, zero.
double focal_length_prior_weight = 0;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about use variance std as parameters and CovarianceWeighted wrapper where std = 1/weight

double principal_point_prior_weight = 0;
double extra_params_prior_weight = 0;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Going with "weight" is probably fine here. The alternative would be "stddev". Maybe add a biref note about how these weights relate to expected standard deviations of the priors?


// Whether to constrain the camera parameters to bounds that are consistent
// with Camera::HasBogusParams, such that the intrinsics cannot leave the
// region that the bogus parameter filter considers valid. Parameters that
// already violate the bounds are clamped into them.
bool bound_camera_params = false;

// Bounds for the camera parameters, only used if bound_camera_params is set.
// The focal length bounds are relative to the maximum image dimension.
double min_focal_length_ratio = 0.1;
double max_focal_length_ratio = 10.0;
double max_extra_param = 1.0;

// Solver backend to use for bundle adjustment.
BundleAdjustmentBackend backend = BundleAdjustmentBackend::CERES;

Expand Down
Loading
Loading