From c32fb79a38d2acd7d94c1ab31cbd9a8e204b56fb Mon Sep 17 00:00:00 2001 From: Piero Toffanin Date: Fri, 13 Dec 2019 19:40:04 +0000 Subject: [PATCH] OpenSfM multi band NVM export --- opendm/types.py | 7 ++----- stages/mvstex.py | 2 +- stages/run_opensfm.py | 31 ++++++++++++++++++++++++++----- 3 files changed, 29 insertions(+), 11 deletions(-) diff --git a/opendm/types.py b/opendm/types.py index 7652f79e..1ccf8dc1 100644 --- a/opendm/types.py +++ b/opendm/types.py @@ -87,7 +87,6 @@ class ODM_Photo: if cit in tags: self.band_index = int(tags[cit]) self.width, self.height = get_image_size.get_image_size(_path_file) - print(self) # From https://github.com/mapillary/OpenSfM/blob/master/opensfm/exif.py def get_xmp(self, file): @@ -328,8 +327,8 @@ class ODM_Tree(object): self.opensfm_bundle_list = io.join_paths(self.opensfm, 'list_r000.out') self.opensfm_image_list = io.join_paths(self.opensfm, 'image_list.txt') self.opensfm_reconstruction = io.join_paths(self.opensfm, 'reconstruction.json') - self.opensfm_reconstruction_nvm = io.join_paths(self.opensfm, 'reconstruction.nvm') - self.opensfm_model = io.join_paths(self.opensfm, 'depthmaps/merged.ply') + self.opensfm_reconstruction_nvm = io.join_paths(self.opensfm, 'undistorted/reconstruction.nvm') + self.opensfm_model = io.join_paths(self.opensfm, 'undistorted/depthmaps/merged.ply') self.opensfm_transformation = io.join_paths(self.opensfm, 'geocoords_transformation.txt') # mve @@ -354,8 +353,6 @@ class ODM_Tree(object): self.odm_texuring_log = 'odm_texturing_log.txt' # odm_georeferencing - self.odm_georeferencing_latlon = io.join_paths( - self.odm_georeferencing, 'latlon.txt') self.odm_georeferencing_coords = io.join_paths( self.odm_georeferencing, 'coords.txt') self.odm_georeferencing_gcp = gcp_file or io.find('gcp_list.txt', self.root_path) diff --git a/stages/mvstex.py b/stages/mvstex.py index 54a93a37..4078aaf4 100644 --- a/stages/mvstex.py +++ b/stages/mvstex.py @@ -74,7 +74,7 @@ class ODMMvsTexStage(types.ODM_Stage): 'toneMapping': self.params.get('tone_mapping'), 'nadirMode': nadir, 'nadirWeight': 2 ** args.texturing_nadir_weight - 1, - 'nvm_file': io.join_paths(tree.opensfm, "reconstruction.nvm") + 'nvm_file': tree.opensfm_reconstruction_nvm } mvs_tmp_dir = os.path.join(r['out_dir'], 'tmp') diff --git a/stages/run_opensfm.py b/stages/run_opensfm.py index 84e80a7b..07d2aa07 100644 --- a/stages/run_opensfm.py +++ b/stages/run_opensfm.py @@ -57,7 +57,7 @@ class ODMOpenSfMStage(types.ODM_Stage): octx.touch(updated_config_flag_file) # These will be used for texturing / MVS - undistorted_images_path = octx.path("undistorted") + undistorted_images_path = octx.path("undistorted", "images") if not io.dir_exists(undistorted_images_path) or self.rerun(): octx.run('undistort') @@ -66,11 +66,32 @@ class ODMOpenSfMStage(types.ODM_Stage): self.update_progress(80) - if not io.file_exists(tree.opensfm_reconstruction_nvm) or self.rerun(): - octx.run('export_visualsfm --undistorted --points') + if not reconstruction.multi_camera: + if not io.file_exists(tree.opensfm_reconstruction_nvm) or self.rerun(): + octx.run('export_visualsfm --points') + else: + log.ODM_WARNING('Found a valid OpenSfM NVM reconstruction file in: %s' % + tree.opensfm_reconstruction_nvm) else: - log.ODM_WARNING('Found a valid OpenSfM NVM reconstruction file in: %s' % - tree.opensfm_reconstruction_nvm) + # Dump band image lists + log.ODM_INFO("Multiple bands found") + for band in reconstruction.multi_camera: + log.ODM_INFO("Exporting %s band" % band['name']) + image_list_file = octx.path("image_list_%s.txt" % band['name'].lower()) + + if not io.file_exists(image_list_file) or self.rerun(): + with open(image_list_file, "w") as f: + f.write("\n".join([p.filename for p in band['photos']])) + log.ODM_INFO("Wrote %s" % image_list_file) + else: + log.ODM_WARNING("Found a valid image list in %s for %s band" % (image_list_file, band['name'])) + + nvm_file = octx.path("undistorted", "reconstruction_%s.nvm" % band['name'].lower()) + if not io.file_exists(nvm_file) or self.rerun(): + octx.run('export_visualsfm --points --image_list "%s"' % image_list_file) + os.rename(tree.opensfm_reconstruction_nvm, nvm_file) + else: + log.ODM_WARNING("Found a valid NVM file in %s for %s band" % (nvm_file, band['name'])) self.update_progress(85)