From 98939bf06a7a777415c97db380fd110cc36043b7 Mon Sep 17 00:00:00 2001 From: generatedunixname89002005287564 Date: Tue, 14 Nov 2023 06:36:42 -0800 Subject: [PATCH] mapillary Reviewed By: zsol Differential Revision: D51300169 fbshipit-source-id: 30cf2084197dbe6f30d499e06e0f09674d761bad --- annotation_gui_gcp/run_ba.py | 38 +++++++++++++++++++++++++++--------- bin/opensfm_main.py | 12 +++++++++--- bin/plot_matches.py | 21 +++++++++++++------- 3 files changed, 52 insertions(+), 19 deletions(-) diff --git a/annotation_gui_gcp/run_ba.py b/annotation_gui_gcp/run_ba.py index 5e4ad9f09..4e571f8aa 100644 --- a/annotation_gui_gcp/run_ba.py +++ b/annotation_gui_gcp/run_ba.py @@ -8,10 +8,16 @@ import numpy as np import opensfm.reconstruction as orec -from opensfm import dataset, log, multiview, pygeometry, pymap -from opensfm import reconstruction_helpers as helpers -from opensfm import transformations as tf -from opensfm import types +from opensfm import ( + dataset, + log, + multiview, + pygeometry, + pymap, + reconstruction_helpers as helpers, + transformations as tf, + types, +) from opensfm.align import apply_similarity logger = logging.getLogger(__name__) @@ -81,7 +87,9 @@ def resplit_reconstruction(merged, original_reconstructions): return split -def gcp_geopositional_error(gcps: List[pymap.GroundControlPoint], reconstruction: types.Reconstruction): +def gcp_geopositional_error( + gcps: List[pymap.GroundControlPoint], reconstruction: types.Reconstruction +): coords_reconstruction = triangulate_gcps(gcps, reconstruction) out = {} for ix, gcp in enumerate(gcps): @@ -114,7 +122,9 @@ def gcp_geopositional_error(gcps: List[pymap.GroundControlPoint], reconstruction return out -def triangulate_gcps(gcps: List[pymap.GroundControlPoint], reconstruction: types.Reconstruction): +def triangulate_gcps( + gcps: List[pymap.GroundControlPoint], reconstruction: types.Reconstruction +): coords = [] for gcp in gcps: res = multiview.triangulate_gcp( @@ -127,7 +137,11 @@ def triangulate_gcps(gcps: List[pymap.GroundControlPoint], reconstruction: types return coords -def reproject_gcps(gcps: List[pymap.GroundControlPoint], reconstruction: types.Reconstruction, reproj_threshold): +def reproject_gcps( + gcps: List[pymap.GroundControlPoint], + reconstruction: types.Reconstruction, + reproj_threshold, +): output = {} for gcp in gcps: point = multiview.triangulate_gcp( @@ -269,7 +283,9 @@ def bundle_with_fixed_images( for point in reconstruction.points.values(): ba.add_point(point.id, point.coordinates, False) - ba.add_point_prior(point.id, point.coordinates, np.array([100.0, 100.0, 100.0]), False) + ba.add_point_prior( + point.id, point.coordinates, np.array([100.0, 100.0, 100.0]), False + ) for shot_id in reconstruction.shots: shot = reconstruction.get_shot(shot_id) @@ -866,7 +882,7 @@ def align( logger.info("No annotations with large reprojection errors") -if __name__ == "__main__": +def main() -> None: log.setup() args = parse_args() sys.exit( @@ -880,3 +896,7 @@ def align( args.std_threshold, ) ) + + +if __name__ == "__main__": + main() # pragma: no cover diff --git a/bin/opensfm_main.py b/bin/opensfm_main.py index 31249e129..2041e163d 100755 --- a/bin/opensfm_main.py +++ b/bin/opensfm_main.py @@ -1,5 +1,5 @@ import sys -from os.path import abspath, join, dirname +from os.path import abspath, dirname, join sys.path.insert(0, abspath(join(dirname(__file__), ".."))) @@ -21,7 +21,13 @@ def create_default_dataset_context( dataset.clean_up() -if __name__ == "__main__": +def main() -> None: commands.command_runner( - commands.opensfm_commands, create_default_dataset_context, dataset_choices=["opensfm"] + commands.opensfm_commands, + create_default_dataset_context, + dataset_choices=["opensfm"], ) + + +if __name__ == "__main__": + main() # pragma: no cover diff --git a/bin/plot_matches.py b/bin/plot_matches.py index 94f9d7fbf..2fe59174b 100755 --- a/bin/plot_matches.py +++ b/bin/plot_matches.py @@ -3,15 +3,13 @@ import argparse import os.path from itertools import combinations +from typing import List import matplotlib.cm as cm import matplotlib.pyplot as pl import numpy as np -from opensfm import dataset -from opensfm import features -from opensfm import io from numpy import ndarray -from typing import List +from opensfm import dataset, features, io def plot_matches(im1, im2, p1: ndarray, p2: ndarray) -> None: @@ -113,7 +111,8 @@ def plot_matches_for_images(data, image, images) -> None: pl.show() -if __name__ == "__main__": +def main() -> None: + global args, images parser = argparse.ArgumentParser(description="Plot matches between images") parser.add_argument("dataset", help="path to the dataset to be processed") parser.add_argument("--image", help="show tracks for a specific") @@ -124,12 +123,20 @@ def plot_matches_for_images(data, image, images) -> None: parser.add_argument( "--save_figs", help="save figures instead of showing them", action="store_true" ) - args: argparse.Namespace = parser.parse_args() + args = parser.parse_args() data = dataset.DataSet(args.dataset) - images: List[str] = data.images() + images = data.images() if args.graph: plot_graph(data) else: plot_matches_for_images(data, args.image, args.images) + + +args: argparse.Namespace +images: List[str] + + +if __name__ == "__main__": + main() # pragma: no cover