From cdfd25135b23548c4d502ed33e97e8416f8c85fc Mon Sep 17 00:00:00 2001 From: Piero Toffanin Date: Fri, 15 May 2020 14:36:46 -0400 Subject: [PATCH] Report stage Former-commit-id: ee8f7fcb3597cf2ce7740c2232160fd0adf9b3ba --- opendm/config.py | 2 +- opendm/shots.py | 4 +++- opendm/types.py | 2 ++ stages/odm_app.py | 7 +++++-- stages/odm_report.py | 33 +++++++++++++++++++++++++++++++++ stages/run_opensfm.py | 2 +- 6 files changed, 45 insertions(+), 5 deletions(-) create mode 100644 stages/odm_report.py diff --git a/opendm/config.py b/opendm/config.py index 2fcbf8a2..6059699f 100755 --- a/opendm/config.py +++ b/opendm/config.py @@ -11,7 +11,7 @@ import sys # parse arguments processopts = ['dataset', 'split', 'merge', 'opensfm', 'mve', 'odm_filterpoints', 'odm_meshing', 'mvs_texturing', 'odm_georeferencing', - 'odm_dem', 'odm_orthophoto'] + 'odm_dem', 'odm_orthophoto', 'odm_report'] with open(io.join_paths(context.root_path, 'VERSION')) as version_file: __version__ = version_file.read().strip() diff --git a/opendm/shots.py b/opendm/shots.py index 397cb82c..cfd75202 100644 --- a/opendm/shots.py +++ b/opendm/shots.py @@ -14,7 +14,7 @@ def get_origin(shot): """The origin of the pose in world coordinates.""" return -get_rotation_matrix(np.array(shot['rotation'])).T.dot(np.array(shot['translation'])) -def extract_shots_from_opensfm(reconstruction_file, geocoords_transformation_file=None, utm_srs=None): +def get_geojson_shots_from_opensfm(reconstruction_file, geocoords_transformation_file=None, utm_srs=None): """ Extract shots from OpenSfM's reconstruction.json """ @@ -77,3 +77,5 @@ def extract_shots_from_opensfm(reconstruction_file, geocoords_transformation_fil else: raise RuntimeError("%s does not exist." % reconstruction_file) +def merge_geojson_shots(geojson_shots_files): + pass \ No newline at end of file diff --git a/opendm/types.py b/opendm/types.py index 43b4f5b7..08ae1bf7 100644 --- a/opendm/types.py +++ b/opendm/types.py @@ -220,6 +220,8 @@ class ODM_Tree(object): self.odm_25dgeoreferencing = io.join_paths(self.root_path, 'odm_georeferencing_25d') self.odm_filterpoints = io.join_paths(self.root_path, 'odm_filterpoints') self.odm_orthophoto = io.join_paths(self.root_path, 'odm_orthophoto') + self.odm_report = io.join_paths(self.root_path, 'odm_report') + # important files paths diff --git a/stages/odm_app.py b/stages/odm_app.py index 6e69deaf..84ac753b 100644 --- a/stages/odm_app.py +++ b/stages/odm_app.py @@ -17,6 +17,7 @@ from odm_orthophoto import ODMOrthoPhotoStage from odm_dem import ODMDEMStage from odm_filterpoints import ODMFilterPoints from splitmerge import ODMSplitStage, ODMMergeStage +from odm_report import ODMReport class ODMApp: @@ -57,7 +58,8 @@ class ODMApp: dem = ODMDEMStage('odm_dem', args, progress=90.0, max_concurrency=args.max_concurrency, verbose=args.verbose) - orthophoto = ODMOrthoPhotoStage('odm_orthophoto', args, progress=100.0) + orthophoto = ODMOrthoPhotoStage('odm_orthophoto', args, progress=98.0) + report = ODMReport('odm_report', args, progress=100.0) # Normal pipeline self.first_stage = dataset @@ -77,7 +79,8 @@ class ODMApp: .connect(texturing) \ .connect(georeferencing) \ .connect(dem) \ - .connect(orthophoto) + .connect(orthophoto) \ + .connect(report) # # SLAM pipeline # # TODO: this is broken and needs work diff --git a/stages/odm_report.py b/stages/odm_report.py new file mode 100644 index 00000000..1043445f --- /dev/null +++ b/stages/odm_report.py @@ -0,0 +1,33 @@ +import os + +from opendm import log +from opendm import io +from opendm import system +from opendm import types +from opendm.shots import get_geojson_shots_from_opensfm +import json + + +class ODMReport(types.ODM_Stage): + def process(self, args, outputs): + tree = outputs['tree'] + reconstruction = outputs['reconstruction'] + + if not os.path.exists(tree.odm_report): system.mkdir_p(tree.odm_report) + + shots_geojson = os.path.join(tree.odm_report, "shots.geojson") + if not io.file_exists(shots_geojson) or self.rerun(): + # Extract geographical camera shots + if reconstruction.is_georeferenced(): + shots = get_geojson_shots_from_opensfm(tree.opensfm_reconstruction, tree.opensfm_transformation, reconstruction.get_proj_srs()) + else: + # Psuedo geo + shots = get_geojson_shots_from_opensfm(tree.opensfm_reconstruction) + + with open(shots_geojson, "w") as fout: + fout.write(json.dumps(shots)) + + logger.info("Wrote %s" % shots_geojson) + else: + log.ODM_WARNING('Found a valid shots file in: %s' % + tree.shots_geojson) \ No newline at end of file diff --git a/stages/run_opensfm.py b/stages/run_opensfm.py index e806c655..7ceefd89 100644 --- a/stages/run_opensfm.py +++ b/stages/run_opensfm.py @@ -126,7 +126,7 @@ class ODMOpenSfMStage(types.ODM_Stage): octx.run('export_geocoords --transformation --proj \'%s\'' % reconstruction.georef.proj4()) else: log.ODM_WARNING("Will skip exporting %s" % tree.opensfm_transformation) - + if args.optimize_disk_space: os.remove(octx.path("tracks.csv")) os.remove(octx.path("undistorted", "tracks.csv"))