From fe96407e9e81285f18ae454624027877c9f02a3d Mon Sep 17 00:00:00 2001 From: Piero Toffanin Date: Tue, 8 Dec 2020 11:37:25 -0500 Subject: [PATCH] Fix re-run logic --- stages/run_opensfm.py | 33 +++++++++++++++++++++------------ 1 file changed, 21 insertions(+), 12 deletions(-) diff --git a/stages/run_opensfm.py b/stages/run_opensfm.py index 84cdf2b4..dfb85ad9 100644 --- a/stages/run_opensfm.py +++ b/stages/run_opensfm.py @@ -147,22 +147,31 @@ class ODMOpenSfMStage(types.ODM_Stage): for band in reconstruction.multi_camera: nvm_file = octx.path("undistorted", "reconstruction_%s.nvm" % band['name'].lower()) - img_map = {} - for fname in p2s: + if not io.file_exists(nvm_file) or self.rerun(): + img_map = {} + + if primary_band_name is None: + primary_band_name = multispectral.get_primary_band_name(reconstruction.multi_camera, args.primary_band) + if p2s is None: + s2p, p2s = multispectral.compute_band_maps(reconstruction.multi_camera, primary_band_name) - # Primary band maps to itself - if band['name'] == primary_band_name: - img_map[fname + '.tif'] = fname + '.tif' - else: - band_filename = next((p.filename for p in p2s[fname] if p.band_name == band['name']), None) - - if band_filename is not None: - img_map[fname + '.tif'] = band_filename + '.tif' + for fname in p2s: + + # Primary band maps to itself + if band['name'] == primary_band_name: + img_map[fname + '.tif'] = fname + '.tif' else: - log.ODM_WARNING("Cannot find %s band equivalent for %s" % (band, fname)) + band_filename = next((p.filename for p in p2s[fname] if p.band_name == band['name']), None) - nvm.replace_nvm_images(tree.opensfm_reconstruction_nvm, img_map, nvm_file) + if band_filename is not None: + img_map[fname + '.tif'] = band_filename + '.tif' + else: + log.ODM_WARNING("Cannot find %s band equivalent for %s" % (band, fname)) + nvm.replace_nvm_images(tree.opensfm_reconstruction_nvm, img_map, nvm_file) + else: + log.ODM_WARNING("Found existing NVM file %s" % nvm_file) + self.update_progress(85) # Skip dense reconstruction if necessary and export