def _load_mask_list(self): """Load mask list from mask_list.txt or list masks/ folder.""" mask_list_file = os.path.join(self.data_path, 'mask_list.txt') if os.path.isfile(mask_list_file): with io.open_rt(mask_list_file) as fin: lines = fin.read().splitlines() self._set_mask_list(lines) else: self._set_mask_path(os.path.join(self.data_path, 'masks'))
def _load_image_list(self): """Load image list from image_list.txt or list image/ folder.""" image_list_file = os.path.join(self.data_path, 'image_list.txt') if os.path.isfile(image_list_file): with io.open_rt(image_list_file) as fin: lines = fin.read().splitlines() self._set_image_list(lines) else: self._set_image_path(os.path.join(self.data_path, 'images'))
def images_with_gps(self): with io.open_rt(self._image_list_path()) as csvfile: image_reader = csv.reader( csvfile, delimiter='\t', quotechar='"', quoting=csv.QUOTE_MINIMAL) for image, lat, lon in image_reader: yield image, float(lat), float(lon)
def load_ground_control_points(self): """Load ground control points. It uses reference_lla to convert the coordinates to topocentric reference frame. """ exif = {image: self.load_exif(image) for image in self.images()} reference = self.load_reference() with io.open_rt(self._ground_control_points_file()) as fin: return io.read_ground_control_points_list(fin, reference, exif)
def load_exif(self, image): """ Return extracted exif information, as dictionary, usually with fields: ================ ===== =================================== Field Type Description ================ ===== =================================== width int Width of image, in pixels height int Height of image, in pixels focal_prior float Focal length (real) / sensor width ================ ===== =================================== :param image: Image name, with extension (i.e. 123.jpg) """ with io.open_rt(self._exif_file(image)) as fin: return json.load(fin)
def _transform_dense_point_cloud(self, data, transformation, output): """Apply a transformation to the merged point cloud.""" A, b = transformation[:3, :3], transformation[:3, 3] input_path = os.path.join(data._depthmap_path(), 'merged.ply') output_path = os.path.join(data.data_path, output) with io.open_rt(input_path) as fin: with io.open_wt(output_path) as fout: for i, line in enumerate(fin): if i < 13: fout.write(line) else: x, y, z, nx, ny, nz, red, green, blue = line.split() x, y, z = np.dot(A, map(float, [x, y, z])) + b nx, ny, nz = np.dot(A, map(float, [nx, ny, nz])) fout.write( "{} {} {} {} {} {} {} {} {}\n".format( x, y, z, nx, ny, nz, red, green, blue))
def load_tracks_graph(self, filename=None): """Return graph (networkx data structure) of tracks""" with io.open_rt(self._tracks_graph_file(filename)) as fin: return load_tracks_graph(fin)
def load_reconstruction(self, filename=None): with io.open_rt(self._reconstruction_file(filename)) as fin: reconstructions = io.reconstructions_from_json(io.json_load(fin)) return reconstructions
def load_undistorted_reconstruction(self): filename = os.path.join(self.data_path, "reconstruction.json") with io.open_rt(filename) as fin: return io.reconstructions_from_json(io.json_load(fin))
def load_undistorted_shot_ids(self): filename = os.path.join(self.data_path, "undistorted_shot_ids.json") with io.open_rt(filename) as fin: return io.json_load(fin)
def load_report(self, path): """Load a report file as a string.""" with io.open_rt(os.path.join(self._report_path(), path)) as fin: return fin.read()
def images_with_gps(self): with io.open_rt(self._image_list_path()) as csvfile: for line in csvfile: image, lat, lon = line.split(u"\t") yield image, float(lat), float(lon)
def load_match_adjacency_list(self): with io.open_rt(self._match_adjacency_list_file()) as fin: obj = json.load(fin) return obj
def load_camera_models_overrides(self): """Load camera models overrides data.""" with io.open_rt(self._camera_models_overrides_file()) as fin: obj = json.load(fin) return io.cameras_from_json(obj)
def load_camera_models(self): """Return camera models data""" with io.open_rt(self._camera_models_file()) as fin: obj = json.load(fin) return io.cameras_from_json(obj)
def load_camera_models_overrides(self): """Load camera models overrides data.""" with io.open_rt(self._camera_models_overrides_file()) as fin: obj = json.load(fin) return io.cameras_from_json(obj)
def load_reference_lla(self): with io.open_rt(self._reference_lla_path()) as fin: return io.json_load(fin)
def load_reconstruction(self, filename=None): with io.open_rt(self._reconstruction_file(filename)) as fin: reconstructions = io.reconstructions_from_json(io.json_load(fin)) return reconstructions
def load_exif(self, image): """Load pre-extracted image exif metadata.""" with io.open_rt(self._exif_file(image)) as fin: return json.load(fin)
def load_reference_lla(self): with io.open_rt(self._reference_lla_path()) as fin: return io.json_load(fin)
def load_rig_assignments(self): """Return rig assignments data""" with io.open_rt(self._rig_assignments_file()) as fin: return json.load(fin)
def load_camera_models(self): """Return camera models data""" with io.open_rt(self._camera_models_file()) as fin: obj = json.load(fin) return io.cameras_from_json(obj)
def load_tracks_graph(self, filename=None): """Return graph (networkx data structure) of tracks""" with io.open_rt(self._tracks_graph_file(filename)) as fin: return tracking.load_tracks_graph(fin)
def load_exif_overrides(self): """Load EXIF overrides data.""" with io.open_rt(self._exif_overrides_file()) as fin: return json.load(fin)
def images_with_gps(self): with io.open_rt(self._image_list_path()) as csvfile: for line in csvfile: image, lat, lon = line.split(u'\t') yield image, float(lat), float(lon)
def load_exif_overrides(self): """Load EXIF overrides data.""" with io.open_rt(self._exif_overrides_file()) as fin: return json.load(fin)
def load_report(self, path): """Load a report file as a string.""" with io.open_rt(os.path.join(self._report_path(), path)) as fin: return fin.read()
import json from opensfm import context from opensfm import io with io.open_rt(context.SENSOR) as f: sensor_data = io.json_load(f) # Convert model types to lower cases for easier query keys = [k.lower() for k in sensor_data.keys()] values = sensor_data.values() sensor_data = dict(zip(keys, values))
def load_rig_models(self): """Return rig models data""" with io.open_rt(self._rig_models_file()) as fin: return json.load(fin)