camera
¶
Top-level entry-point for the pupil_labs.camera package
Modules:
-
radial– -
utils–
Classes:
-
Camera–A camera model with radial distortion.
Functions:
-
get_perspective_transform–Computes a perspective transformation matrix from four point correspondences.
-
perspective_transform–Applies a perspective transformation to 2D points.
Camera
¶
Camera(pixel_width: int, pixel_height: int, camera_matrix: CameraMatrixLike, distortion_coefficients: DistortionCoefficientsLike | None = None, extrinsics_affine_matrix: AffineMatrixLike | None = None, use_optimal_camera_matrix: bool = False)
A camera model with radial distortion.
Methods:
-
distort_image–Distorts the provided image.
-
distort_points–Distorts 2D image points using the camera's intrinsics.
-
project_points–Projects 3D points onto the 2D image plane using the camera's intrinsics.
-
undistort_image–Undistorts the provided image.
-
undistort_points–Undistorts 2D image points using the camera's intrinsics.
-
unproject_points–Unprojects 2D image points to 3D space using the camera's intrinsics.
Attributes:
-
optimal_camera_matrix(CameraMatrix) –The "optimal" camera matrix for undistorting images.
Source code in src/pupil_labs/camera/radial.py
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 | |
optimal_camera_matrix
cached
property
¶
optimal_camera_matrix: CameraMatrix
The "optimal" camera matrix for undistorting images.
This method uses OpenCV's getOptimalNewCameraMatrix to calculate a new camera
matrix that maximizes the retirval of sensible pixels in the undistortion
process, while avoiding "virtual" black pixels stemming from outside the
captured distorted image.
distort_image
¶
distort_image(image: Image, use_optimal_camera_matrix: bool | None = None) -> Image
Distorts the provided image.
This implementation uses cv2.remap with a precomputed map, instead of cv2.undistort. This is significantly faster when undistorting multiple images because the undistortion maps are computed only once.
Parameters:
-
image(Image) –Image array
-
use_optimal_camera_matrix(bool | None, default:None) –If True applies optimal camera matrix
Source code in src/pupil_labs/camera/radial.py
194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 | |
distort_points
¶
distort_points(points_2d: Points2DLike, use_optimal_camera_matrix: bool | None = None) -> Points2D
Distorts 2D image points using the camera's intrinsics.
Parameters:
-
points_2d(Points2DLike) –Array-like of 2D point(s) to be distorted.
-
use_optimal_camera_matrix(bool | None, default:None) –If True applies optimal camera matrix
Source code in src/pupil_labs/camera/radial.py
366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 | |
project_points
¶
project_points(points_3d: Points3DLike, use_distortion: bool = True, use_optimal_camera_matrix: bool | None = None, use_extrinsics: bool = False) -> Points2D
Projects 3D points onto the 2D image plane using the camera's intrinsics.
Parameters:
-
points_3d(Points3DLike) –Array of 3D point(s) to be projected.
-
use_distortion(bool, default:True) –If True, applies distortion using the camera's distortion coefficients. If False, ignores distortion.
-
use_optimal_camera_matrix(bool | None, default:None) –If True applies optimal camera matrix
-
use_extrinsics(bool, default:False) –If True, transforms the 3D points from world to camera coordinates using the camera's extrinsic parameters before projection. If False (default), assumes that the 3D points are already in camera coordinates.
Source code in src/pupil_labs/camera/radial.py
298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 | |
undistort_image
¶
undistort_image(image: Image, use_optimal_camera_matrix: bool | None = None) -> Image
Undistorts the provided image.
This implementation uses cv2.remap with a precomputed map, instead of cv2.undistort. This is significantly faster when undistorting multiple images because the undistortion maps are computed only once.
Parameters:
-
image(Image) –Image array
-
use_optimal_camera_matrix(bool | None, default:None) –If True applies optimal camera matrix
Source code in src/pupil_labs/camera/radial.py
164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 | |
undistort_points
¶
undistort_points(points_2d: Points2DLike, use_optimal_camera_matrix: bool | None = None) -> Points2D
Undistorts 2D image points using the camera's intrinsics.
Parameters:
-
points_2d(Points2DLike) –Array-like of 2D point(s) to be undistorted.
-
use_optimal_camera_matrix(bool | None, default:None) –If True applies optimal camera matrix
Source code in src/pupil_labs/camera/radial.py
340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 | |
unproject_points
¶
unproject_points(points_2d: Points2DLike, use_distortion: bool = True, use_optimal_camera_matrix: bool | None = None) -> Points3D
Unprojects 2D image points to 3D space using the camera's intrinsics.
Parameters:
-
points_2d(Points2DLike) –Array-like of 2D point(s) to be unprojected.
-
use_distortion(bool, default:True) –If True, applies distortion correction using the camera's distortion coefficients. If False, ignores distortion correction.
-
use_optimal_camera_matrix(bool | None, default:None) –If True applies optimal camera matrix
Source code in src/pupil_labs/camera/radial.py
268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 | |
get_perspective_transform
¶
get_perspective_transform(points1: Points2DLike, points2: Points2DLike) -> NDArray[float64]
Computes a perspective transformation matrix from four point correspondences.
Parameters:
-
points1(Points2DLike) –Array-like of 4 source 2D points.
-
points2(Points2DLike) –Array-like of 4 destination 2D points.
Returns:
-
NDArray[float64]–3x3 perspective transformation matrix.
Source code in src/pupil_labs/camera/utils.py
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 | |
perspective_transform
¶
perspective_transform(points: Points2DLike, transform: NDArray[floating]) -> Points2D
Applies a perspective transformation to 2D points.
Parameters:
-
points(Points2DLike) –Array-like of 2D point(s) to be transformed.
-
transform(NDArray[floating]) –3x3 perspective transformation matrix.
Returns:
-
Points2D–Transformed 2D points with the same shape as input.
Source code in src/pupil_labs/camera/utils.py
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 | |