From eebe39a5896de989fdaed6965b38986d69d47a5b Mon Sep 17 00:00:00 2001 From: Oleg Alexandrov Date: Wed, 11 Dec 2024 12:09:58 -0800 Subject: [PATCH] Can produce dense matches in --correlator-mode --- docs/stereodefault.rst | 8 ++++---- docs/tools/correlator.rst | 5 +++++ src/asp/Tools/parallel_stereo | 18 +++++++++++++----- src/asp/Tools/stereo | 4 +++- src/asp/Tools/stereo_tri.cc | 14 +++++++++++++- 5 files changed, 38 insertions(+), 11 deletions(-) diff --git a/docs/stereodefault.rst b/docs/stereodefault.rst index 2d69d6f0d..6f44fcfa9 100644 --- a/docs/stereodefault.rst +++ b/docs/stereodefault.rst @@ -830,10 +830,10 @@ num-matches-from-disp-triplets (*integer*) (default = 0) (:numref:`heights_from_dem`). num-matches-from-disparity (*integer*) (default = 0) - Create a match file with roughly this many points uniformly sampled from - the stereo disparity. The matches are between original images - (that is, before any alignment or map-projection). See also - ``num-matches-from-disp-triplets``. + Create a match file with roughly this many points uniformly sampled from the + stereo disparity. The matches are between original images (that is, before + any alignment or map-projection). These can be used in bundle adjustment + See also ``num-matches-from-disp-triplets``. compute-point-cloud-center-only Only compute the center of triangulated point cloud and exit. Hence, diff --git a/docs/tools/correlator.rst b/docs/tools/correlator.rst index 74ee32095..19e7bc656 100644 --- a/docs/tools/correlator.rst +++ b/docs/tools/correlator.rst @@ -30,6 +30,11 @@ Example:: This will create the filtered subpixel disparity ``run_corr/run-F.tif`` (:numref:`outputfiles`). +If the options ``--num-matches-from-disparity`` or +``--num-matches-from-disp-triplets`` are specified, dense matches from disparity +will be produced (:numref:`stereodefault`). These can be used in bundle adjustment +(:numref:`dense_ip`). + All the usual options of ``parallel_stereo`` apply. See :numref:`nextsteps` for a discussion regarding various quality vs speed tradeoffs. Since the images are assumed to be aligned, the diff --git a/src/asp/Tools/parallel_stereo b/src/asp/Tools/parallel_stereo index 0939d43c5..91bf91ffc 100644 --- a/src/asp/Tools/parallel_stereo +++ b/src/asp/Tools/parallel_stereo @@ -700,7 +700,7 @@ def normal_run(prog, opt, args, **kw): if code != 0: raise Exception('Stereo step ' + kw['msg'] + ' failed') -def keepOnlySpecified(keep_only, out_prefix, subdirs): +def keepOnlySpecified(keep_only, out_prefix, subdirs, settings): """ Merge all VRTs and wipe any files the user does not want to keep. """ @@ -734,6 +734,11 @@ def keepOnlySpecified(keep_only, out_prefix, subdirs): return for f in keep_files: + + if int(settings['correlator_mode'][0]) != 0 and 'PC.tif' in f: + # No PC.tif in correlator-mode + continue + print("Keeping: " + f) if isVrt(f): f_merged = os.path.splitext(f)[0] + "_merged.tif" @@ -768,7 +773,7 @@ def keepOnlySpecified(keep_only, out_prefix, subdirs): # It looks useful to print the final cloud, as the messages above # can be quite verbose. pc_file = glob.glob(out_prefix + "-PC.tif") - if len(pc_file) > 0: + if len(pc_file) > 0 and int(settings['correlator_mode'][0]) == 0: print("Output point cloud: " + pc_file[0]) def set_collar_size(new_collar_size, args, settings): @@ -1265,7 +1270,9 @@ if __name__ == '__main__': sys.exit() # TODO(oalexan1): Must wipe the subdirs! - if int(settings['correlator_mode'][0]) != 0: + if int(settings['correlator_mode'][0]) != 0 and \ + '--num-matches-from-disparity' not in parallel_args and \ + '--num-matches-from-disp-triplets' not in parallel_args: # Skip triangulation, but continue further down with cleanup. print("Skipping triangulation with --correlator-mode.") else: @@ -1286,14 +1293,15 @@ if __name__ == '__main__': subdirs = create_subdirs_symlink(opt, args, settings) # Run triangulation on multiple machines spawn_to_nodes(step, opt, settings, parallel_args, subdirs) - build_vrt('stereo_tri', opt, args, settings, georef, "-PC.tif", "-PC.tif") + if int(settings['correlator_mode'][0]) == 0: + build_vrt('stereo_tri', opt, args, settings, georef, "-PC.tif", "-PC.tif") # If the run concluded successfully, merge and wipe if (opt.stop_point > Step.tri): if len(subdirs) == 0: # If this was not created by now, do it now subdirs = create_subdirs_symlink(opt, args, settings) - keepOnlySpecified(opt.keep_only, out_prefix, subdirs) + keepOnlySpecified(opt.keep_only, out_prefix, subdirs, settings) # End main process case else: diff --git a/src/asp/Tools/stereo b/src/asp/Tools/stereo index 89ae6daf6..326776446 100644 --- a/src/asp/Tools/stereo +++ b/src/asp/Tools/stereo @@ -194,7 +194,9 @@ if __name__ == '__main__': if (opt.stop_point <= step): sys.exit() - if int(settings['correlator_mode'][0]) != 0: + if int(settings['correlator_mode'][0]) != 0 and \ + '--num-matches-from-disparity' not in args and \ + '--num-matches-from-disp-triplets' not in args: print("Skipping triangulation with --correlator-mode.") sys.exit() diff --git a/src/asp/Tools/stereo_tri.cc b/src/asp/Tools/stereo_tri.cc index a0a9f78d0..69e202fd0 100644 --- a/src/asp/Tools/stereo_tri.cc +++ b/src/asp/Tools/stereo_tri.cc @@ -697,6 +697,12 @@ void stereo_triangulation(std::string const& output_prefix, cameras); } + // In correlator mode, can go no further + if (asp::stereo_settings().correlator_mode) { + vw_out() << "\t--> Skipping triangulation in correlator mode.\n"; + return; + } + if (is_map_projected) vw_out() << "\t--> Inputs are map projected." << std::endl; @@ -776,6 +782,10 @@ void stereo_triangulation(std::string const& output_prefix, left_aligned_bathy_mask, right_aligned_bathy_mask), universe_radius_func); + // In correlator mode, can go no further + if (asp::stereo_settings().correlator_mode) + return; + // If we crop the left and right images, at each run we must // recompute the cloud center, as the cropping windows may have changed. bool crop_left = (stereo_settings().left_image_crop_win != BBox2i(0, 0, 0, 0)); @@ -835,7 +845,9 @@ void stereo_triangulation(std::string const& output_prefix, int main(int argc, char* argv[]) { - if (asp::stereo_settings().correlator_mode) { + if (asp::stereo_settings().correlator_mode && + asp::stereo_settings().num_matches_from_disparity <= 0 && + asp::stereo_settings().num_matches_from_disp_triplets <= 0) { vw_out() << "The triangulation step is skipped with --correlator-mode.\n"; return 0; }