|
1 | 1 | from enum import IntEnum
|
2 | 2 | from typing import Optional, Tuple
|
3 | 3 |
|
| 4 | +import numpy as np |
| 5 | + |
4 | 6 | import k4a_module
|
5 | 7 |
|
6 | 8 | from .config import ColorResolution, DepthMode
|
@@ -157,3 +159,28 @@ def transformation_handle(self) -> object:
|
157 | 159 | raise K4AException("Cannot create transformation handle")
|
158 | 160 | self._transformation_handle = handle
|
159 | 161 | return self._transformation_handle
|
| 162 | + |
| 163 | + def get_camera_matrix(self, camera: CalibrationType) -> np.ndarray: |
| 164 | + """ |
| 165 | + Get the camera matrix (in OpenCV compatible format) for the color or depth camera |
| 166 | + """ |
| 167 | + if camera not in [CalibrationType.COLOR, CalibrationType.DEPTH]: |
| 168 | + raise ValueError("Camera matrix only available for color and depth cameras.") |
| 169 | + params = k4a_module.calibration_get_intrinsics(self._calibration_handle, self.thread_safe, camera) |
| 170 | + if len(params) != 14: |
| 171 | + raise ValueError("Unknown camera calibration type") |
| 172 | + |
| 173 | + cx, cy, fx, fy = params[:4] |
| 174 | + return np.array([[fx, 0, cx], [0, fy, cy], [0, 0, 1]]) |
| 175 | + |
| 176 | + def get_distortion_coefficients(self, camera: CalibrationType) -> np.ndarray: |
| 177 | + """ |
| 178 | + Get the distortion coefficients (in OpenCV compatible format) for the color or depth camera |
| 179 | + """ |
| 180 | + if camera not in [CalibrationType.COLOR, CalibrationType.DEPTH]: |
| 181 | + raise ValueError("Distortion coefficients only available for color and depth cameras.") |
| 182 | + params = k4a_module.calibration_get_intrinsics(self._calibration_handle, self.thread_safe, camera) |
| 183 | + if len(params) != 14: |
| 184 | + raise ValueError("Unknown camera calibration type") |
| 185 | + |
| 186 | + return np.array([params[4], params[5], params[13], params[12], *params[6:10]]) |
0 commit comments