def camera_from_json(key, obj): """ Read camera from a json object """ pt = obj.get('projection_type', 'perspective') if pt == 'perspective': camera = types.PerspectiveCamera() camera.id = key camera.width = obj.get('width', 0) camera.height = obj.get('height', 0) camera.focal = obj['focal'] camera.k1 = obj.get('k1', 0.0) camera.k2 = obj.get('k2', 0.0) return camera if pt == 'brown': camera = types.BrownPerspectiveCamera() camera.id = key camera.width = obj.get('width', 0) camera.height = obj.get('height', 0) camera.focal_x = obj['focal_x'] camera.focal_y = obj['focal_y'] camera.c_x = obj.get('c_x', 0.0) camera.c_y = obj.get('c_y', 0.0) camera.k1 = obj.get('k1', 0.0) camera.k2 = obj.get('k2', 0.0) camera.p1 = obj.get('p1', 0.0) camera.p2 = obj.get('p2', 0.0) camera.k3 = obj.get('k3', 0.0) return camera elif pt == 'fisheye': camera = types.FisheyeCamera() camera.id = key camera.width = obj.get('width', 0) camera.height = obj.get('height', 0) camera.focal = obj['focal'] camera.k1 = obj.get('k1', 0.0) camera.k2 = obj.get('k2', 0.0) return camera elif pt == 'dual': camera = types.DualCamera() camera.id = key camera.width = obj.get('width', 0) camera.height = obj.get('height', 0) camera.focal = obj['focal'] camera.k1 = obj.get('k1', 0.0) camera.k2 = obj.get('k2', 0.0) camera.transition = obj.get('transition', 0.5) return camera elif pt in ['equirectangular', 'spherical']: camera = types.SphericalCamera() camera.id = key camera.width = obj['width'] camera.height = obj['height'] return camera else: raise NotImplementedError
def _get_dual_camera(): camera = types.DualCamera() camera.width = 800 camera.height = 600 camera.focal = 0.3 camera.k1 = -0.1 camera.k2 = 0.01 camera.transition = 0.5 camera_cpp = pygeometry.Camera.create_dual(camera.transition, camera.focal, camera.k1, camera.k2) return camera, camera_cpp
def camera_from_exif_metadata(metadata, data): ''' Create a camera object from exif metadata ''' pt = metadata.get('projection_type', 'perspective').lower() if pt == 'perspective': calib = (hard_coded_calibration(metadata) or focal_ratio_calibration(metadata) or default_calibration(data)) camera = types.PerspectiveCamera() camera.id = metadata['camera'] camera.width = metadata['width'] camera.height = metadata['height'] camera.projection_type = pt camera.focal = calib['focal'] camera.k1 = calib['k1'] camera.k2 = calib['k2'] return camera elif pt == 'brown': calib = (hard_coded_calibration(metadata) or focal_xy_calibration(metadata) or default_calibration(data)) camera = types.BrownPerspectiveCamera() camera.id = metadata['camera'] camera.width = metadata['width'] camera.height = metadata['height'] camera.projection_type = pt camera.focal_x = calib['focal_x'] camera.focal_y = calib['focal_y'] camera.c_x = calib['c_x'] camera.c_y = calib['c_y'] camera.k1 = calib['k1'] camera.k2 = calib['k2'] camera.p1 = calib['p1'] camera.p2 = calib['p2'] camera.k3 = calib['k3'] return camera elif pt == 'fisheye': calib = (hard_coded_calibration(metadata) or focal_ratio_calibration(metadata) or default_calibration(data)) camera = types.FisheyeCamera() camera.id = metadata['camera'] camera.width = metadata['width'] camera.height = metadata['height'] camera.projection_type = pt camera.focal = calib['focal'] camera.k1 = calib['k1'] camera.k2 = calib['k2'] return camera elif pt == 'dual': calib = (hard_coded_calibration(metadata) or focal_ratio_calibration(metadata) or default_calibration(data)) camera = types.DualCamera() camera.id = metadata['camera'] camera.width = metadata['width'] camera.height = metadata['height'] camera.projection_type = pt camera.focal = calib['focal'] camera.k1 = calib['k1'] camera.k2 = calib['k2'] camera.transition = calib['transition'] return camera elif pt in ['equirectangular', 'spherical']: camera = types.SphericalCamera() camera.id = metadata['camera'] camera.width = metadata['width'] camera.height = metadata['height'] return camera else: raise ValueError("Unknown projection type: {}".format(pt))