def test_reconstructions_from_json_consistency(): with open(filename) as fin: obj_before = json.loads(fin.read()) obj_after = io.reconstructions_to_json( io.reconstructions_from_json(obj_before)) assert obj_before[0]["cameras"] == obj_after[0]["cameras"] # need to explicitly use np.allclose because of numerical # differences on 3D coordinates (shot and points) for key, shot in obj_before[0]["shots"].items(): for attr in shot: obj1 = obj_before[0]["shots"][key][attr] obj2 = obj_after[0]["shots"][key][attr] if attr in ["translation", "rotation"]: assert np.allclose(np.array(obj1), np.array(obj2)) else: assert obj1 == obj2 for key, point in obj_before[0]["points"].items(): for attr in point: if attr == "reprojection_error": continue obj1 = obj_before[0]["points"][key][attr] obj2 = obj_after[0]["points"][key][attr] if attr == "coordinates": assert np.allclose(np.array(obj1), np.array(obj2)) else: assert obj1 == obj2
def _(self): reconstruction_path = str(get_undistorted_path() / "reconstruction.json") neighbors_path = str(get_undistorted_path() / "neighbors.json") with io.open_rt(reconstruction_path) as fin: reconstruction = io.reconstructions_from_json(io.json_load(fin))[0] self.shot_id = "1579044395.47_img_00088.jpg_perspective_view_front" self.lonely_shot_id = "1579044395.47_img_00088.jpg_perspective_view_back" self.shot = reconstruction.shots[self.shot_id] self.lonely_shot = reconstruction.shots[self.lonely_shot_id] self.shots_dict = reconstruction.shots self.expected_shot_ids = [ "1579044395.47_img_00089.jpg_perspective_view_back", "1579044395.47_img_00081.jpg_perspective_view_bottom", "1579044395.47_img_00079.jpg_perspective_view_front" ] self.neighbors_dict = { self.shot_id: self.expected_shot_ids, self.lonely_shot_id: [] } with io.open_wt(neighbors_path) as fp: io.json_dump(self.neighbors_dict, fp) self.data = some_data() self.reconstruction = reconstruction
def load_reconstruction( self, filename: Optional[str] = None) -> List[types.Reconstruction]: with self.io_handler.open_rt( self._reconstruction_file(filename)) as fin: reconstructions = io.reconstructions_from_json(io.json_load(fin)) return reconstructions
def test_reconstructions_from_json(): with open(filename) as fin: obj = json.loads(fin.read()) reconstructions = io.reconstructions_from_json(obj) assert len(reconstructions) == 1 assert len(reconstructions[0].cameras) == 1 assert len(reconstructions[0].shots) == 3 assert len(reconstructions[0].points) == 1588
def test_reconstructions_from_json() -> None: with open(filename) as fin: obj = json.loads(fin.read()) reconstructions = io.reconstructions_from_json(obj) assert len(reconstructions) == 1 assert len(reconstructions[0].cameras) == 1 assert len(reconstructions[0].shots) == 3 assert len(reconstructions[0].points) == 1430 assert len(reconstructions[0].rig_cameras) == 1 assert len(reconstructions[0].rig_instances) == 3
def test_reconstructions_from_json(): with open(filename) as fin: obj = json.loads(fin.read()) reconstructions = io.reconstructions_from_json(obj) assert len(reconstructions) == 1 assert len(reconstructions[0].cameras) == 1 assert len(reconstructions[0].shots) == 3 assert len(reconstructions[0].points) == 1588 assert len(reconstructions[0].rig_models) == 1 assert len( reconstructions[0].rig_models["rig_model"].get_rig_cameras()) == 1 assert len(reconstructions[0].rig_instances) == 3
def test_panoshots_consistency() -> None: rec_before = types.Reconstruction() camera1 = pygeometry.Camera.create_spherical() camera1.id = "camera1" rec_before.add_camera(camera1) rec_before.create_shot("shot1", "camera1") rec_before.create_shot("shot2", "camera1") rec_before.create_pano_shot("shot1", "camera1") rec_before.create_pano_shot("shot2", "camera1") rec_before.create_pano_shot("shot4", "camera1") rec_before.create_pano_shot("shot3", "camera1") json_data = io.reconstructions_to_json([rec_before]) rec_after = io.reconstructions_from_json(json_data)[0] utils.assert_reconstructions_equal(rec_before, rec_after)
def load_reconstruction(self, filename=None): with open(self.__reconstruction_file(filename)) as fin: reconstructions = io.reconstructions_from_json(json.load(fin)) return reconstructions
def load_reconstructions(recon_file_path): with open(recon_file_path) as fin: reconstructions = io.reconstructions_from_json(json.load(fin)) return reconstructions
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 test_reconstruction_to_ply(): with open(filename) as fin: obj = json.loads(fin.read()) reconstructions = io.reconstructions_from_json(obj) ply = io.reconstruction_to_ply(reconstructions[0]) assert len(ply.splitlines()) > len(reconstructions[0].points)
def load_undistorted_reconstruction(self) -> List[types.Reconstruction]: filename = os.path.join(self.data_path, "reconstruction.json") with self.io_handler.open_rt(filename) as fin: return io.reconstructions_from_json(io.json_load(fin))
for key, value in gps_points_dict.items(): x, y, z = geo.topocentric_from_lla( value[0], value[1], value[2], reflla['latitude'], reflla['longitude'], reflla['altitude']) topocentric_gps_points_dict[key] = (x, y, z) return topocentric_gps_points_dict # Entry point if __name__ == "__main__": debug = True import matplotlib.pyplot as plt import matplotlib.image as mpimg show_num = -1 if len(sys.argv) > 1: show_num = int(sys.argv[1]) with open('reconstruction.json') as fin: reconstructions = io.reconstructions_from_json(json.load(fin)) reconstructions = sorted(reconstructions, key=lambda x: -len(x.shots)) if show_num == -1: debug_plot_reconstructions(reconstructions) else: debug_plot_reconstruction(reconstructions[show_num])