|
6 | 6 | import typing as T
|
7 | 7 |
|
8 | 8 | import aiohttp
|
| 9 | +import numpy as np |
9 | 10 | import websockets
|
10 | 11 |
|
11 | 12 | import pupil_labs # noqa: F401
|
@@ -165,6 +166,35 @@ async def __aexit__(
|
165 | 166 | def _create_client_session(self):
|
166 | 167 | self.session = aiohttp.ClientSession()
|
167 | 168 |
|
| 169 | + async def get_calibration(self) -> np.ndarray: |
| 170 | + """ |
| 171 | + :raises pupil_labs.realtime_api.device.DeviceError: if the request fails |
| 172 | + """ |
| 173 | + async with self.session.get(self.api_url(APIPath.CALIBRATION)) as response: |
| 174 | + if response.status != 200: |
| 175 | + raise DeviceError(response.status, "Failed to fetch calibration") |
| 176 | + |
| 177 | + raw_data = await response.read() |
| 178 | + return np.frombuffer( |
| 179 | + raw_data, |
| 180 | + np.dtype( |
| 181 | + [ |
| 182 | + ("version", "u1"), |
| 183 | + ("serial", "6a"), |
| 184 | + ("scene_camera_matrix", "(3,3)d"), |
| 185 | + ("scene_distortion_coefficients", "8d"), |
| 186 | + ("scene_extrinsics_affine_matrix", "(4,4)d"), |
| 187 | + ("right_camera_matrix", "(3,3)d"), |
| 188 | + ("right_distortion_coefficients", "8d"), |
| 189 | + ("right_extrinsics_affine_matrix", "(4,4)d"), |
| 190 | + ("left_camera_matrix", "(3,3)d"), |
| 191 | + ("left_distortion_coefficients", "8d"), |
| 192 | + ("left_extrinsics_affine_matrix", "(4,4)d"), |
| 193 | + ("crc", "u4"), |
| 194 | + ] |
| 195 | + ), |
| 196 | + ) |
| 197 | + |
168 | 198 |
|
169 | 199 | class StatusUpdateNotifier:
|
170 | 200 | def __init__(self, device: Device, callbacks: T.List[UpdateCallback]) -> None:
|
|
0 commit comments