Skip to content

Commit

Permalink
Minor robustification of checks
Browse files Browse the repository at this point in the history
  • Loading branch information
oleg-alexandrov committed Nov 3, 2023
1 parent df9eae7 commit c42b571
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 18 deletions.
2 changes: 1 addition & 1 deletion docs/bundle_adjustment.rst
Original file line number Diff line number Diff line change
Expand Up @@ -893,7 +893,7 @@ Apply the alignment transform to the pairwise bundle-adjusted cameras as well,
and use these cameras for the refinement of intrinsics, with the ground constraint
being the mosaic of these aligned DEMs.

It is suggested to examine how each individual aligned DEM differs from the
It is suggested to examine how each aligned DEM differs from the
reference, and the same for their mosaic. The hope is that the mosaicking will
average out the errors in the individual DEMs.

Expand Down
17 changes: 11 additions & 6 deletions src/asp/Core/BundleAdjustUtils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
/// \file BundleAdjustUtils.cc
///

#include <asp/Core/BundleAdjustUtils.h>

#include <vw/Core/Log.h>
#include <vw/Camera/CameraModel.h>
#include <vw/BundleAdjustment/ControlNetwork.h>
Expand All @@ -26,7 +28,7 @@
#include <vw/FileIO/DiskImageView.h>
#include <vw/Cartography/CameraBBox.h>
#include <vw/BundleAdjustment/CameraRelation.h>
#include <asp/Core/BundleAdjustUtils.h>
#include <vw/InterestPoint/Matcher.h>

#include <string>

Expand Down Expand Up @@ -302,8 +304,9 @@ std::string asp::bundle_adjust_file_name(std::string const& prefix,
return prefix + "-" + fs::path(file).stem().string() + ".adjust";
}

/// Ensure that no images, camera files, or adjustment names are duplicate.
/// That will cause the output files to overwrite each other!
/// Ensure that the basename (without extension) of all images, camera files, or
/// adjustment names are different. Later these will be used for match files,
/// and we want match files corresponding to different images to be different.
void asp::check_for_duplicates(std::vector<std::string> const& image_files,
std::vector<std::string> const& camera_files,
std::string const& out_prefix) {
Expand All @@ -314,9 +317,11 @@ void asp::check_for_duplicates(std::vector<std::string> const& image_files,
std::set<std::string> img_set, cam_set, adj_set;
for (size_t i = 0; i < camera_files.size(); i++) {

std::string const & img = image_files[i]; // alias
std::string const & cam = camera_files[i]; // alias
std::string adj = asp::bundle_adjust_file_name(out_prefix, img, cam);
std::string img = vw::ip::strip_path("", image_files[i]);
std::string cam = vw::ip::strip_path("", camera_files[i]);
std::string adj = vw::ip::strip_path(out_prefix,
asp::bundle_adjust_file_name(out_prefix,
img, cam));

if (img_set.find(img) != img_set.end())
vw_throw(vw::ArgumentErr() << "Found duplicate image: " << img << "\n");
Expand Down
10 changes: 5 additions & 5 deletions src/asp/Tools/bundle_adjust.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2169,7 +2169,9 @@ void handle_arguments(int argc, char *argv[], Options& opt) {
po::variables_map vm =
asp::check_command_line(argc, argv, opt, general_options, general_options,
positional, positional_desc, usage,
allow_unregistered, unregistered);
allow_unregistered, unregistered);

boost::to_lower(opt.stereo_session);

// Separate out GCP files
opt.gcp_files = asp::get_files_with_ext(opt.image_files, ".gcp", true);
Expand Down Expand Up @@ -2216,12 +2218,11 @@ void handle_arguments(int argc, char *argv[], Options& opt) {
vw_throw(ArgumentErr() << "Must have as many cameras as we have images.\n");
}

// If the DG session is used and errors are to be propagated, must use CSM.
// Must happen before copy_to_asp_settings() and before cameras are loaded.
if (opt.propagate_errors)
if (opt.propagate_errors && opt.stereo_session.find("dg") != std::string::npos)
opt.dg_use_csm = true;

// TODO: Check for duplicates in opt.image_files!

if (opt.image_files.empty())
vw_throw( ArgumentErr() << "Missing input image files.\n"
<< usage << general_options );
Expand Down Expand Up @@ -2250,7 +2251,6 @@ void handle_arguments(int argc, char *argv[], Options& opt) {
inline_adjustments = true;
}

boost::to_lower(opt.stereo_session);

opt.camera_type = BaCameraType_Other;
if (inline_adjustments) {
Expand Down
17 changes: 11 additions & 6 deletions src/asp/Tools/stereo.cc
Original file line number Diff line number Diff line change
Expand Up @@ -393,9 +393,12 @@ namespace asp {
cfg_options), vm);
po::notify(vm);
} catch (po::error const& e) {
vw::vw_throw(vw::ArgumentErr() << "Error parsing configuration file:\n" << e.what() << "\n");
vw::vw_throw(vw::ArgumentErr()
<< "Error parsing configuration file:\n" << e.what() << "\n");
}

boost::to_lower(opt.stereo_session);

asp::stereo_settings().validate();

// Do this early, before any cameras are loaded
Expand All @@ -404,17 +407,19 @@ namespace asp {
if (!stereo_settings().dg_use_csm) {
vw::Vector2 const& v = asp::stereo_settings().horizontal_stddev; // alias
if (v[0] <= 0 || v[1] <= 0) {
// Have to use the CSM model to propagate the errors
// Will print a message later, only when we know the camera is actually DG
stereo_settings().dg_use_csm = true;
print_dg_csm_cov_message = true;
// For DG, have to use the CSM model to propagate the errors. Will
// print a message later.
if (opt.stereo_session.find("dg") != std::string::npos) {
stereo_settings().dg_use_csm = true;
print_dg_csm_cov_message = true;
}
}
}
}

if (stereo_settings().correlator_mode) {
stereo_settings().alignment_method = "none"; // images are assumed aligned
opt.stereo_session = "rpc"; // since inputs are images this seems simpler
opt.stereo_session = "rpc"; // since inputs are images this seems simpler

if (stereo_settings().propagate_errors)
vw::vw_throw(vw::ArgumentErr() << "Cannot propagate errors in correlator mode.\n");
Expand Down

0 comments on commit c42b571

Please sign in to comment.