def run_dataset(data: DataSetBase) -> None: """Link matches pair-wise matches into tracks.""" start = timer() features, colors, segmentations, instances = tracking.load_features( data, data.images()) features_end = timer() matches = tracking.load_matches(data, data.images()) matches_end = timer() tracks_manager = tracking.create_tracks_manager( features, colors, segmentations, instances, matches, data.config["min_track_length"], ) tracks_end = timer() data.save_tracks_manager(tracks_manager) write_report( data, tracks_manager, features_end - start, matches_end - features_end, tracks_end - matches_end, )
def run_dataset(data: DataSetBase): """Compute features for all images.""" start = timer() features_processing.run_features_processing(data, data.images(), False) end = timer() write_report(data, end - start)
def run_dataset(data: DataSetBase, input, output) -> None: recs_base = data.load_reconstruction(input) if len(recs_base) == 0: return rec_base = recs_base[0] tracks_manager = data.load_tracks_manager() rec_base.add_correspondences_from_tracks_manager(tracks_manager) images = data.images() remaining_images = set(images) - set(rec_base.shots) gcp = data.load_ground_control_points() report = {} rec_report = {} report["extend_reconstruction"] = [rec_report] rec, rec_report["grow"] = reconstruction.grow_reconstruction( data, tracks_manager, rec_base, remaining_images, gcp, ) rec_report["num_remaining_images"] = len(remaining_images) report["not_reconstructed_images"] = list(remaining_images) data.save_reconstruction([rec], output) data.save_report(io.json_dumps(report), "reconstruction.json")
def undistort_reconstruction( tracks_manager: Optional[pymap.TracksManager], reconstruction: types.Reconstruction, data: DataSetBase, udata: UndistortedDataSet, ) -> Dict[pymap.Shot, List[pymap.Shot]]: all_images = set(data.images()) image_format = data.config["undistorted_image_format"] urec = types.Reconstruction() urec.points = reconstruction.points urec.reference = reconstruction.reference rig_instance_count = itertools.count() utracks_manager = pymap.TracksManager() logger.debug("Undistorting the reconstruction") undistorted_shots = {} for shot in reconstruction.shots.values(): if shot.id not in all_images: logger.warning( f"Not undistorting {shot.id} as it is missing from the dataset's input images." ) continue if shot.camera.projection_type == "perspective": urec.add_camera(perspective_camera_from_perspective(shot.camera)) subshots = [get_shot_with_different_camera(urec, shot, image_format)] elif shot.camera.projection_type == "brown": urec.add_camera(perspective_camera_from_brown(shot.camera)) subshots = [get_shot_with_different_camera(urec, shot, image_format)] elif shot.camera.projection_type in ["fisheye", "fisheye_opencv"]: urec.add_camera(perspective_camera_from_fisheye(shot.camera)) subshots = [get_shot_with_different_camera(urec, shot, image_format)] elif pygeometry.Camera.is_panorama(shot.camera.projection_type): subshot_width = int(data.config["depthmap_resolution"]) subshots = perspective_views_of_a_panorama( shot, subshot_width, urec, image_format, rig_instance_count ) else: logger.warning( f"Not undistorting {shot.id} with unknown camera type." ) continue for subshot in subshots: if tracks_manager: add_subshot_tracks(tracks_manager, utracks_manager, shot, subshot) undistorted_shots[shot.id] = subshots udata.save_undistorted_reconstruction([urec]) if tracks_manager: udata.save_undistorted_tracks_manager(utracks_manager) udata.save_undistorted_shot_ids( { shot_id: [ushot.id for ushot in ushots] for shot_id, ushots in undistorted_shots.items() } ) return undistorted_shots
def write_report(data: DataSetBase, wall_time: float): image_reports = [] for image in data.images(): try: txt = data.load_report("features/{}.json".format(image)) image_reports.append(io.json_loads(txt)) except IOError: logger.warning("No feature report image {}".format(image)) report = {"wall_time": wall_time, "image_reports": image_reports} data.save_report(io.json_dumps(report), "features.json")
def run_dataset(data: DataSetBase) -> None: """Match features between image pairs.""" images = data.images() start = timer() pairs_matches, preport = matching.match_images(data, {}, images, images) matching.save_matches(data, images, pairs_matches) matching.clear_cache() end = timer() write_report(data, preport, list(pairs_matches.keys()), end - start)
def invent_reference_from_gps_and_gcp( data: DataSetBase, images: Optional[List[str]] = None) -> geo.TopocentricConverter: lat, lon, alt = 0.0, 0.0, 0.0 wlat, wlon, walt = 0.0, 0.0, 0.0 if images is None: images = data.images() for image in images: d = data.load_exif(image) if "gps" in d and "latitude" in d["gps"] and "longitude" in d["gps"]: w = 1.0 / max(0.01, d["gps"].get("dop", 15)) lat += w * d["gps"]["latitude"] lon += w * d["gps"]["longitude"] wlat += w wlon += w if "altitude" in d["gps"]: alt += w * d["gps"]["altitude"] walt += w if not wlat and not wlon: for gcp in data.load_ground_control_points(): lat += gcp.lla["latitude"] lon += gcp.lla["longitude"] wlat += 1 wlon += 1 if gcp.has_altitude: alt += gcp.lla["altitude"] walt += 1 if wlat: lat /= wlat if wlon: lon /= wlon if walt: alt /= walt return geo.TopocentricConverter(lat, lon, 0) # Set altitude manually.
def run_dataset(data: DataSetBase): """Extract metadata from images' EXIF tag.""" exif_overrides = {} if data.exif_overrides_exists(): exif_overrides = data.load_exif_overrides() camera_models = {} for image in data.images(): if data.exif_exists(image): logging.info("Loading existing EXIF for {}".format(image)) d = data.load_exif(image) else: logging.info("Extracting EXIF for {}".format(image)) d = _extract_exif(image, data) if image in exif_overrides: d.update(exif_overrides[image]) data.save_exif(image, d) if d["camera"] not in camera_models: camera = exif.camera_from_exif_metadata(d, data) camera_models[d["camera"]] = camera # Override any camera specified in the camera models overrides file. if data.camera_models_overrides_exists(): overrides = data.load_camera_models_overrides() if "all" in overrides: for key in camera_models: camera_models[key] = copy.copy(overrides["all"]) camera_models[key].id = key else: for key, value in overrides.items(): camera_models[key] = value data.save_camera_models(camera_models)