Skip to content

Commit

Permalink
Factor out some params used by jitter solving and bundle adjustment
Browse files Browse the repository at this point in the history
  • Loading branch information
oleg-alexandrov committed Aug 26, 2024
1 parent 2afc5cd commit 2005818
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 41 deletions.
31 changes: 18 additions & 13 deletions src/asp/Camera/BundleAdjustCamera.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,14 +83,17 @@ struct BaBaseOptions: public vw::GdalWriteOptions {
ip_edge_buffer_percent, max_num_reference_points, num_passes;
bool have_overlap_list;
std::set<std::pair<std::string, std::string>> overlap_list;
std::string overlap_list_file, auto_overlap_params, datum_str, proj_str;
std::string overlap_list_file, auto_overlap_params, datum_str, proj_str,
csv_format_str, csv_srs, csv_proj4_str, disparity_list;
bool match_first_to_last, single_threaded_cameras,
update_isis_cubes_with_csm_state;
double min_triangulation_angle, max_init_reproj_error, robust_threshold, parameter_tolerance;
double forced_triangulation_distance, min_triangulation_angle, max_init_reproj_error,
robust_threshold, parameter_tolerance;
double heights_from_dem_uncertainty, reference_terrain_weight,
heights_from_dem_robust_threshold, camera_weight, rotation_weight,
camera_position_weight, camera_position_robust_threshold,
tri_weight, tri_robust_threshold, camera_position_uncertainty_power;
tri_weight, tri_robust_threshold, camera_position_uncertainty_power,
max_disp_error;
std::vector<vw::Vector2> camera_position_uncertainty;
vw::Vector<double, 4> remove_outliers_params;
BACameraType camera_type;
Expand All @@ -100,16 +103,18 @@ struct BaBaseOptions: public vw::GdalWriteOptions {
vw::cartography::Datum datum;
vw::BBox2 proj_win; // Limit input triangulated points to this projwin

BaBaseOptions(): min_triangulation_angle(0.0), camera_position_weight(0.0),
camera_position_robust_threshold(0.0), camera_weight(-1.0),
rotation_weight(0.0), tri_weight(0.0),
robust_threshold(0.0), min_matches(0),
num_iterations(0), num_passes(0),
overlap_limit(0), have_overlap_list(false),
camera_type(BaCameraType_Other), max_num_reference_points(-1),
datum(vw::cartography::Datum(asp::UNSPECIFIED_DATUM,
"User Specified Spheroid",
"Reference Meridian", 1, 1, 0)) {}
BaBaseOptions():
forced_triangulation_distance(-1),
min_triangulation_angle(0.0), camera_position_weight(0.0),
camera_position_robust_threshold(0.0), camera_weight(-1.0),
rotation_weight(0.0), tri_weight(0.0),
robust_threshold(0.0), min_matches(0),
num_iterations(0), num_passes(0),
overlap_limit(0), have_overlap_list(false),
camera_type(BaCameraType_Other), max_num_reference_points(-1),
datum(vw::cartography::Datum(asp::UNSPECIFIED_DATUM,
"User Specified Spheroid",
"Reference Meridian", 1, 1, 0)) {}
};

// A structure to hold percentiles of given sorted values. This sorts the inputs.
Expand Down
10 changes: 6 additions & 4 deletions src/asp/Camera/BundleAdjustCostFuns.cc
Original file line number Diff line number Diff line change
Expand Up @@ -662,8 +662,10 @@ void add_disparity_residual_block(vw::Vector3 const& reference_xyz,
residual_ptrs);
if (opt.camera_type == asp::BaCameraType_Other) {

boost::shared_ptr<CeresBundleModelBase> left_wrapper (new AdjustedCameraBundleModel(left_camera_model ));
boost::shared_ptr<CeresBundleModelBase> right_wrapper(new AdjustedCameraBundleModel(right_camera_model));
boost::shared_ptr<CeresBundleModelBase>
left_wrapper (new AdjustedCameraBundleModel(left_camera_model));
boost::shared_ptr<CeresBundleModelBase>
right_wrapper(new AdjustedCameraBundleModel(right_camera_model));
ceres::CostFunction* cost_function =
BaDispXyzError::Create(opt.max_disp_error, opt.reference_terrain_weight,
reference_xyz, interp_disp, left_wrapper, right_wrapper,
Expand Down Expand Up @@ -913,7 +915,7 @@ void addTriConstraint(asp::BaOptions const& opt,
// stereo with the option --unalign-disparity. If there are n images, there must
// be n-1 disparities, from each image to the next.
void addReferenceTerrainCostFunction(
asp::BaOptions & opt,
asp::BaOptions & opt,
asp::BAParams & param_storage,
ceres::Problem & problem,
std::vector<vw::Vector3> & reference_vec,
Expand Down Expand Up @@ -1010,7 +1012,7 @@ void addReferenceTerrainCostFunction(

// Call function to select the appropriate Ceres residual block to add.
add_disparity_residual_block(reference_xyz, interp_disp[icam],
icam, icam+1, // left icam and right icam
icam, icam + 1, // left icam and right icam
param_storage, opt, problem);
}
tpc.report_incremental_progress(inc_amount);
Expand Down
16 changes: 0 additions & 16 deletions src/asp/Camera/BundleAdjustCostFuns.h
Original file line number Diff line number Diff line change
Expand Up @@ -433,22 +433,6 @@ struct RotTransError {
/// From the input options select the correct Ceres loss function.
ceres::LossFunction* get_loss_function(std::string const& cost_function, double th);

/// Add error source for projecting a 3D point into the camera.
void add_reprojection_residual_block(vw::Vector2 const& observation,
vw::Vector2 const& pixel_sigma,
int point_index, int camera_index,
asp::BAParams & param_storage,
asp::BaOptions const& opt,
ceres::Problem & problem);

/// Add residual block for the error using reference xyz.
void add_disparity_residual_block(vw::Vector3 const& reference_xyz,
vw::ImageViewRef<DispPixelT> const& interp_disp,
int left_cam_index, int right_cam_index,
asp::BAParams & param_storage,
asp::BaOptions const& opt,
ceres::Problem & problem);

// Pixel reprojection error. Note: cam_residual_counts and num_pixels_per_cam
// serve different purposes.
void addPixelReprojCostFun(asp::BaOptions const& opt,
Expand Down
10 changes: 5 additions & 5 deletions src/asp/Camera/BundleAdjustOptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ struct BaOptions: public asp::BaBaseOptions {
std::string cnet_file, vwip_prefix,
cost_function, mapprojected_data, gcp_from_mapprojected;
int ip_per_tile, ip_per_image, matches_per_tile;
double forced_triangulation_distance, overlap_exponent, ip_triangulation_max_error;
double overlap_exponent, ip_triangulation_max_error;
int instance_count, instance_index, num_random_passes, ip_num_ransac_iterations;
bool save_intermediate_cameras, approximate_pinhole_intrinsics,
init_camera_using_gcp, disable_pinhole_gcp_init,
Expand All @@ -40,23 +40,23 @@ struct BaOptions: public asp::BaBaseOptions {
ip_normalize_tiles, ip_debug_images, stop_after_stats, stop_after_matching,
skip_matching, apply_initial_transform_only, save_vwip, propagate_errors;
std::string camera_position_file, initial_transform_file,
csv_format_str, csv_srs, csv_proj4_str, disparity_list,

dem_file_for_overlap;
double semi_major, semi_minor, position_filter_dist;
std::string remove_outliers_params_str;
std::vector<double> intrinsics_limits;
boost::shared_ptr<vw::ba::ControlNetwork> cnet;
int ip_detect_method, num_scales;
double epipolar_threshold; // Max distance from epipolar line to search for IP matches.
double ip_inlier_factor, ip_uniqueness_thresh, nodata_value, max_disp_error,
double ip_inlier_factor, ip_uniqueness_thresh, nodata_value,
auto_overlap_buffer, pct_for_overlap, min_distortion;
bool skip_rough_homography, enable_rough_homography, disable_tri_filtering,
enable_tri_filtering, no_datum, individually_normalize, use_llh_error,
force_reuse_match_files, no_poses_from_nvm, save_cnet_as_csv, aster_use_csm;
vw::Vector2 elevation_limit; // Expected range of elevation to limit results to.
vw::BBox2 lon_lat_limit; // Limit the triangulated interest points to this lonlat range
vw::Matrix<double> initial_transform;
std::string fixed_cameras_indices_str, flann_method;
std::string fixed_cameras_indices_str, flann_method;
std::set<int> fixed_cameras_indices;
asp::IntrinsicOptions intrinsics_options;
vw::Vector2i matches_per_tile_params;
Expand All @@ -66,7 +66,7 @@ struct BaOptions: public asp::BaBaseOptions {
// Make sure all values are initialized, even though they will be
// over-written later.
BaOptions(): ip_per_tile(0), ip_per_image(0),
forced_triangulation_distance(-1), overlap_exponent(0),
overlap_exponent(0),
save_intermediate_cameras(false),
fix_gcp_xyz(false), solve_intrinsics(false),
semi_major(0), semi_minor(0), position_filter_dist(-1),
Expand Down
4 changes: 2 additions & 2 deletions src/asp/Tools/bundle_adjust.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1770,15 +1770,15 @@ void handle_arguments(int argc, char *argv[], asp::BaOptions& opt) {
if (opt.reference_terrain != "") {
std::string file_type = asp::get_cloud_type(opt.reference_terrain);
if (file_type == "DEM") {
// TODO(oalexan1): What if a different planet is specified in the images?
vw::cartography::GeoReference georef;
bool is_good = vw::cartography::read_georeference(georef, opt.reference_terrain);
if (!is_good)
vw_throw(ArgumentErr()
<< "The reference terrain DEM does not have a georeference.\n");
// Ensure the datum read from the DEM agrees with the one from the cameras/user
if (is_good && have_datum)
vw::checkDatumConsistency(opt.datum, georef.datum(), warn_only);
if (opt.datum_str == ""){
if (opt.datum_str == "") {
opt.datum = georef.datum();
opt.datum_str = opt.datum.name();
have_datum = true;
Expand Down
1 change: 0 additions & 1 deletion src/asp/Tools/jitter_solve.cc
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ struct Options: public asp::BaBaseOptions {
use_initial_rig_transforms;
double quat_norm_weight, anchor_weight, roll_weight, yaw_weight;
std::map<int, int> cam2group;
double forced_triangulation_distance;
};

void handle_arguments(int argc, char *argv[], Options& opt, rig::RigSet & rig) {
Expand Down

0 comments on commit 2005818

Please sign in to comment.