def test_shot_measurement_set(): m1 = pymap.ShotMeasurements() _helper_populate_metadata(m1) m2 = pymap.ShotMeasurements() # Test setting metadata with other metadata m2.set(m1) # Check that m2 has the same values as m1 assert_metadata_equal(m1, m2) m3 = pymap.ShotMeasurements() m1.set(m3) # Now m1 should be completely reset assert_metadata_equal(m1, m3)
def test_shot_measurement_setter_and_getter(): m1 = pymap.ShotMeasurements() # Test basic functionality _help_measurement_test(m1, "capture_time", np.random.rand(1)) _help_measurement_test(m1, "gps_position", np.random.rand(3)) _help_measurement_test(m1, "gps_accuracy", np.random.rand(1)) _help_measurement_test(m1, "compass_accuracy", np.random.rand(1)) _help_measurement_test(m1, "compass_angle", np.random.rand(1)) _help_measurement_test(m1, "accelerometer", np.random.rand(3)) _help_measurement_test(m1, "orientation", random.randint(0, 100)) _help_measurement_test(m1, "sequence_key", "key_test")
def test_shot_measurement_setter_and_getter(): m1 = pymap.ShotMeasurements() # Test basic functionality _help_measurement_test(m1, 'capture_time', np.random.rand(1)) _help_measurement_test(m1, 'gps_position', np.random.rand(3)) _help_measurement_test(m1, 'gps_accuracy', np.random.rand(1)) _help_measurement_test(m1, 'compass_accuracy', np.random.rand(1)) _help_measurement_test(m1, 'compass_angle', np.random.rand(1)) _help_measurement_test(m1, 'accelerometer', np.random.rand(3)) _help_measurement_test(m1, 'orientation', random.randint(0, 100)) _help_measurement_test(m1, 'sequence_key', "key_test")
def test_reconstruction_class_initialization() -> None: # Instantiate Reconstruction reconstruction = types.Reconstruction() focal = 0.9722222222222222 k1 = 0.006094395128698237 k2 = -0.0004952058188617129 # Instantiate camera instrinsics camera = pygeometry.Camera.create_perspective(focal, k1, k2) camera.id = "apple iphone 4s back camera 4.28mm f/2.4" camera.height = 2448 camera.width = 3264 reconstruction.add_camera(camera) # Instantiate GPS data metadata = pymap.ShotMeasurements() metadata.orientation.value = 1 metadata.capture_time.value = 0.0 metadata.gps_accuracy.value = 5.0 # pyre-fixme[8]: Attribute has type `ndarray`; used as `List[float]`. metadata.gps_position.value = [ 1.0815875281451939, -0.96510451436708888, 1.2042133903991235, ] # pyre-fixme[8]: Attribute has type `ndarray`; used as `List[float]`. metadata.accelerometer.value = [0.1, 0.9, 0.0] metadata.compass_angle.value = 270.0 metadata.compass_accuracy.value = 15.0 metadata.sequence_key.value = "a_sequence_key" # Instantiate shots # pyre-fixme[6]: For 1st param expected `ndarray` but got `List[float]`. # pyre-fixme[6]: For 2nd param expected `ndarray` but got `List[float]`. pose0 = pygeometry.Pose([0.0, 0.0, 0.0], [0.0, 0.0, 0.0]) shot0 = reconstruction.create_shot("0", camera.id, pose0) shot0.metadata = metadata # pyre-fixme[6]: For 1st param expected `ndarray` but got `List[float]`. # pyre-fixme[6]: For 2nd param expected `ndarray` but got `List[float]`. pose1 = pygeometry.Pose([0.0, 0.0, 0.0], [-1.0, 0.0, 0.0]) shot1 = reconstruction.create_shot("1", camera.id, pose1) shot1.metadata = metadata # TEST assert len(reconstruction.cameras) == 1 assert len(reconstruction.shots) == 2 assert len(reconstruction.points) == 0 assert reconstruction.get_camera(camera.id) is not None assert reconstruction.get_shot(shot0.id) is not None assert reconstruction.get_shot(shot1.id) is not None
def exif_to_metadata( exif: Dict[str, Any], use_altitude: bool, reference: types.TopocentricConverter ) -> pymap.ShotMeasurements: """Construct a metadata object from raw EXIF tags (as a dict).""" metadata = pymap.ShotMeasurements() gps = exif.get("gps") if gps and "latitude" in gps and "longitude" in gps: lat, lon = gps["latitude"], gps["longitude"] if use_altitude: alt = min([oexif.maximum_altitude, gps.get("altitude", 2.0)]) else: alt = 2.0 # Arbitrary value used to align the reconstruction x, y, z = reference.to_topocentric(lat, lon, alt) metadata.gps_position.value = np.array([x, y, z]) metadata.gps_accuracy.value = gps.get("dop", 15.0) if metadata.gps_accuracy.value == 0.0: metadata.gps_accuracy.value = 15.0 else: metadata.gps_position.value = np.array([0.0, 0.0, 0.0]) metadata.gps_accuracy.value = 999999.0 opk = exif.get("opk") if opk and "omega" in opk and "phi" in opk and "kappa" in opk: omega, phi, kappa = opk["omega"], opk["phi"], opk["kappa"] metadata.opk_angles.value = np.array([omega, phi, kappa]) metadata.opk_accuracy.value = opk.get("accuracy", 1.0) metadata.orientation.value = exif.get("orientation", 1) if "accelerometer" in exif: metadata.accelerometer.value = exif["accelerometer"] if "compass" in exif: metadata.compass_angle.value = exif["compass"]["angle"] if "accuracy" in exif["compass"]: metadata.compass_accuracy.value = exif["compass"]["accuracy"] if "capture_time" in exif: metadata.capture_time.value = exif["capture_time"] if "skey" in exif: metadata.sequence_key.value = exif["skey"] return metadata
def test_reconstruction_class_initialization(): # Instantiate Reconstruction reconstruction = types.Reconstruction() focal = 0.9722222222222222 k1 = 0.006094395128698237 k2 = -0.0004952058188617129 # Instantiate camera instrinsics camera = pygeometry.Camera.create_perspective(focal, k1, k2) camera.id = 'apple iphone 4s back camera 4.28mm f/2.4' camera.height = 2448 camera.width = 3264 reconstruction.add_camera(camera) # Instantiate GPS data metadata = pymap.ShotMeasurements() metadata.orientation.value = 1 metadata.capture_time.value = 0.0 metadata.gps_accuracy.value = 5.0 metadata.gps_position.value = [1.0815875281451939, -0.96510451436708888, 1.2042133903991235] metadata.accelerometer.value = [0.1, 0.9, 0.0] metadata.compass_angle.value = 270.0 metadata.compass_accuracy.value = 15.0 metadata.sequence_key.value = 'a_sequence_key' # Instantiate shots pose0 = pygeometry.Pose([0.0, 0.0, 0.0], [0.0, 0.0, 0.0]) shot0 = reconstruction.create_shot('0', camera.id, pose0) shot0.metadata = metadata pose1 = pygeometry.Pose([0.0, 0.0, 0.0], [-1.0, 0.0, 0.0]) shot1 = reconstruction.create_shot('1', camera.id, pose1) shot1.metadata = metadata # TEST assert len(reconstruction.cameras) == 1 assert len(reconstruction.shots) == 2 assert len(reconstruction.points) == 0 assert reconstruction.get_camera(camera.id) is not None assert reconstruction.get_shot(shot0.id) is not None assert reconstruction.get_shot(shot1.id) is not None
def json_to_pymap_metadata(obj): metadata = pymap.ShotMeasurements() if obj.get("orientation") is not None: metadata.orientation.value = obj.get("orientation") if obj.get("capture_time") is not None: metadata.capture_time.value = obj.get("capture_time") if obj.get("gps_dop") is not None: metadata.gps_accuracy.value = obj.get("gps_dop") if obj.get("gps_position") is not None: metadata.gps_position.value = obj.get("gps_position") if obj.get("skey") is not None: metadata.sequence_key.value = obj.get("skey") if obj.get("accelerometer") is not None: metadata.accelerometer.value = obj.get("accelerometer") if obj.get("compass") is not None: compass = obj.get("compass") if "angle" in compass: metadata.compass_angle.value = compass["angle"] if "accuracy" in compass: metadata.compass_accuracy.value = compass["accuracy"] return metadata
def exif_to_metadata( exif: Dict[str, Any], use_altitude: bool, reference: types.TopocentricConverter) -> pymap.ShotMeasurements: """Construct a metadata object from raw EXIF tags (as a dict).""" metadata = pymap.ShotMeasurements() if "gps" in exif and "latitude" in exif["gps"] and "longitude" in exif[ "gps"]: lat = exif["gps"]["latitude"] lon = exif["gps"]["longitude"] if use_altitude: alt = min( [oexif.maximum_altitude, exif["gps"].get("altitude", 2.0)]) else: alt = 2.0 # Arbitrary value used to align the reconstruction x, y, z = reference.to_topocentric(lat, lon, alt) metadata.gps_position.value = [x, y, z] metadata.gps_accuracy.value = exif["gps"].get("dop", 15.0) if metadata.gps_accuracy.value == 0.0: metadata.gps_accuracy.value = 15.0 else: metadata.gps_position.value = [0.0, 0.0, 0.0] metadata.gps_accuracy.value = 999999.0 metadata.orientation.value = exif.get("orientation", 1) if "accelerometer" in exif: metadata.accelerometer.value = exif["accelerometer"] if "compass" in exif: metadata.compass_angle.value = exif["compass"]["angle"] if "accuracy" in exif["compass"]: metadata.compass_accuracy.value = exif["compass"]["accuracy"] if "capture_time" in exif: metadata.capture_time.value = exif["capture_time"] if "skey" in exif: metadata.sequence_key.value = exif["skey"] return metadata
def get_image_metadata(data, image): """Get image metadata as a ShotMetadata object.""" metadata = pymap.ShotMeasurements() exif = data.load_exif(image) reference = data.load_reference() if "gps" in exif and "latitude" in exif["gps"] and "longitude" in exif[ "gps"]: lat = exif["gps"]["latitude"] lon = exif["gps"]["longitude"] if data.config["use_altitude_tag"]: alt = min( [oexif.maximum_altitude, exif["gps"].get("altitude", 2.0)]) else: alt = 2.0 # Arbitrary value used to align the reconstruction x, y, z = reference.to_topocentric(lat, lon, alt) metadata.gps_position.value = [x, y, z] metadata.gps_accuracy.value = exif["gps"].get("dop", 15.0) if metadata.gps_accuracy.value == 0.0: metadata.gps_accuracy.value = 15.0 else: metadata.gps_position.value = [0.0, 0.0, 0.0] metadata.gps_accuracy.value = 999999.0 metadata.orientation.value = exif.get("orientation", 1) if "accelerometer" in exif: metadata.accelerometer.value = exif["accelerometer"] if "compass" in exif: metadata.compass_angle.value = exif["compass"]["angle"] if "accuracy" in exif["compass"]: metadata.compass_accuracy.value = exif["compass"]["accuracy"] if "capture_time" in exif: metadata.capture_time.value = exif["capture_time"] if "skey" in exif: metadata.sequence_key.value = exif["skey"] return metadata
def get_image_metadata(data, image): """Get image metadata as a ShotMetadata object.""" metadata = pymap.ShotMeasurements() exif = data.load_exif(image) reference = data.load_reference() if ('gps' in exif and 'latitude' in exif['gps'] and 'longitude' in exif['gps']): lat = exif['gps']['latitude'] lon = exif['gps']['longitude'] if data.config['use_altitude_tag']: alt = min([oexif.maximum_altitude, exif['gps'].get('altitude', 2.0)]) else: alt = 2.0 # Arbitrary value used to align the reconstruction x, y, z = reference.to_topocentric(lat, lon, alt) metadata.gps_position.value = [x, y, z] metadata.gps_accuracy.value = exif['gps'].get('dop', 15.0) if metadata.gps_accuracy.value == 0.0: metadata.gps_accuracy.value = 15.0 else: metadata.gps_position.value = [0.0, 0.0, 0.0] metadata.gps_accuracy.value = 999999.0 metadata.orientation.value = exif.get('orientation', 1) if 'accelerometer' in exif: metadata.accelerometer.value = exif['accelerometer'] if 'compass' in exif: metadata.compass_angle.value = exif['compass']['angle'] if 'accuracy' in exif['compass']: metadata.compass_accuracy.value = exif['compass']['accuracy'] if 'capture_time' in exif: metadata.capture_time.value = exif['capture_time'] if 'skey' in exif: metadata.sequence_key.value = exif['skey'] return metadata