Skip to content

Commit

Permalink
Can produce dense matches in --correlator-mode
Browse files Browse the repository at this point in the history
  • Loading branch information
oleg-alexandrov committed Dec 11, 2024
1 parent b1df5fc commit eebe39a
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 11 deletions.
8 changes: 4 additions & 4 deletions docs/stereodefault.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
5 changes: 5 additions & 0 deletions docs/tools/correlator.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 13 additions & 5 deletions src/asp/Tools/parallel_stereo
Original file line number Diff line number Diff line change
Expand Up @@ -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.
"""
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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:
Expand All @@ -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:
Expand Down
4 changes: 3 additions & 1 deletion src/asp/Tools/stereo
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
14 changes: 13 additions & 1 deletion src/asp/Tools/stereo_tri.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit eebe39a

Please sign in to comment.