Skip to content

Commit

Permalink
mapillary
Browse files Browse the repository at this point in the history
Reviewed By: zsol

Differential Revision: D51300169

fbshipit-source-id: 30cf2084197dbe6f30d499e06e0f09674d761bad
  • Loading branch information
generatedunixname89002005287564 authored and facebook-github-bot committed Nov 14, 2023
1 parent 25c04c3 commit 98939bf
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 19 deletions.
38 changes: 29 additions & 9 deletions annotation_gui_gcp/run_ba.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__)
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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(
Expand All @@ -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(
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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(
Expand All @@ -880,3 +896,7 @@ def align(
args.std_threshold,
)
)


if __name__ == "__main__":
main() # pragma: no cover
12 changes: 9 additions & 3 deletions bin/opensfm_main.py
Original file line number Diff line number Diff line change
@@ -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__), "..")))

Expand All @@ -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
21 changes: 14 additions & 7 deletions bin/plot_matches.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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")
Expand All @@ -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

0 comments on commit 98939bf

Please sign in to comment.