def export(reconstruction, tracks_manager, udata: UndistortedDataSet, export_only): exporter = pydense.OpenMVSExporter() for camera in reconstruction.cameras.values(): if camera.projection_type == "perspective": w, h = camera.width, camera.height K = np.array([ [camera.focal * max(w, h), 0, (w - 1.0) / 2.0], [0, camera.focal * max(w, h), (h - 1.0) / 2.0], [0, 0, 1], ]) exporter.add_camera(str(camera.id), K, w, h) for shot in reconstruction.shots.values(): if export_only is not None and shot.id not in export_only: continue if shot.camera.projection_type == "perspective": image_path = udata._undistorted_image_file(shot.id) exporter.add_shot( str(os.path.abspath(image_path)), str(shot.id), str(shot.camera.id), shot.pose.get_rotation_matrix(), shot.pose.get_origin(), ) for point in reconstruction.points.values(): observations = tracks_manager.get_track_observations(point.id) if export_only is not None: shots = [k for k in observations if k in export_only] else: shots = list(observations) if shots: coordinates = np.array(point.coordinates, dtype=np.float64) exporter.add_point(coordinates, shots) io.mkdir_p(udata.data_path + "/openmvs") exporter.export(udata.data_path + "/openmvs/scene.mvs")
def image_path(image, udata: UndistortedDataSet): """Path to the undistorted image relative to the dataset path.""" path = udata._undistorted_image_file(image) return os.path.relpath(path, udata.data_path)