General geometry utilities
Functions:
|
Convert a rotation vector to a rotation matrix. |
Convert a rotation matrix to a rotation vector. |
|
Compute the rigid transform that maps source points to target points. |
|
|
Apply a rigid transform to a set of points. |
Generate 4x4 transformation matrices from a 3D rotations and translations. |
|
Convert 4x4 transformation matrices to vector format. |
|
|
Generate a projection matrix from camera intrinsics and extrinsics. |
|
Convert Euclidean coordinates to homogenous coordinates |
|
Convert homogenous coordinates to Euclidean coordinates |
|
Project 3D points onto the image plane. |
|
Wrapper for cv2.undistortPoints that handles NaNs and batch dimensions. |
|
Triangulate 3D points from 2D correspondences. |
- multicam_calibration.geometry.rodrigues(r)
Convert a rotation vector to a rotation matrix.
- Parameters:
r (array of shape (...,3)) – Rotation vector in axis-angle form.
- Returns:
R – Rotation matrix.
- Return type:
array of shape (…,3,3)
- multicam_calibration.geometry.rodrigues_inv(R)
Convert a rotation matrix to a rotation vector.
- Parameters:
R (array of shape (...,3,3)) – Rotation matrix.
- Returns:
r – Rotation vector in axis-angle form.
- Return type:
array of shape (…,3)
- multicam_calibration.geometry.rigid_transform_from_correspondences(source_points, target_points)
Compute the rigid transform that maps source points to target points.
- Parameters:
source_points (array of shape (..., 3)) – Source points.
target_points (array of shape (..., 3)) – Target points.
- Returns:
t (array of shape (6,)) – Rigid transforms in vector format. The first three elements specify a rotation in axis-angle form and the last three elements specify a translation.
rmsd (float) – Root mean square deviation between the source and target points after applying the rigid transform.
- multicam_calibration.geometry.apply_rigid_transform(transform, points)
Apply a rigid transform to a set of points.
- Parameters:
transform (array of shape (6,) or (4,4)) – Rigid transform in matrix or vector format. In vector format, the first three elements specify a rotation in axis-angle form and the last three elements specify a translation.
points (array of shape (...,3)) – Points to transform.
- Returns:
points_transformed – Transformed points.
- Return type:
array of shape (…,3)
- multicam_calibration.geometry.get_transformation_matrix(t)
Generate 4x4 transformation matrices from a 3D rotations and translations.
- Parameters:
t (array of shape (...,6)) – Rigid transforms in vector format. The first three elements specify a rotation in axis-angle form and the last three elements specify a translation.
- Returns:
T – Transformation matrices.
- Return type:
array of shape (…,4,4)
- multicam_calibration.geometry.get_transformation_vector(T)
Convert 4x4 transformation matrices to vector format.
This function inverts
multicam_calibration.get_transformation_matrix().- Parameters:
T (array of shape (...,4,4)) – Transformation matrices.
- Returns:
t – Rigid transforms in vector format. The first three elements specify a rotation in axis-angle form and the last three elements specify a translation.
- Return type:
array of shape (…,6)
- multicam_calibration.geometry.get_projection_matrix(extrinsics, intrinsics)
Generate a projection matrix from camera intrinsics and extrinsics.
The projection matrix transforms points from world coordinates to image coordinates. It is defined as follows, where K is the camera matrix, R is the rotation matrix, and t is the translation vector.:
P = K [R | t]
- Parameters:
extrinsics (array of shape (6,)) – The transformation from the world coordinate system to the camera’s coordinate system. The first three elements are the rotation vector and the last three elements are the translation vector.
intrinsics (tuple (camera_matrix, dist_coefs)) – Camera intrinsics (see
multicam_calibration.get_intrinsics()).
- Returns:
P – The projection matrix.
- Return type:
array of shape (3, 4)
- multicam_calibration.geometry.euclidean_to_homogenous(x_euclidean)
Convert Euclidean coordinates to homogenous coordinates
..math:
(x_1,...,x_d) \mapsto (x_1,...,x_d, 1)
- Parameters:
x_euclidean (array of shape (...,d)) – Euclidean coordinates.
- Returns:
x_homogenous – Homogenous coordinates.
- Return type:
array of shape (…,d+1)
- multicam_calibration.geometry.homogeneous_to_euclidean(x_homogenous)
Convert homogenous coordinates to Euclidean coordinates
..math:
(x_1,...,x_d, z) \mapsto (x_1/z,...,x_d/z)
- Parameters:
x_homogenous (array of shape (...,d+1)) – Homogenous coordinates.
- Returns:
x_euclidean – Euclidean coordinates.
- Return type:
array of shape (…,d)
- multicam_calibration.geometry.project_points(points, extrinsics, camera_matrix, dist_coefs=None)
Project 3D points onto the image plane.
- Parameters:
points (array of shape (..., 3)) – 3D points in the world coordinate system.
extrinsics (array of shape (6,)) – The transformation from the world coordinate system to the camera’s coordinate system. The first three elements are the rotation vector and the last three elements are the translation vector.
camera_matrix (array of shape (3, 3)) – The camera matrix.
dist_coefs (1d array of length at least 2, optional) – The radial distortion coefficients k1, k2. If None, no distortion is applied.
- Returns:
uvs – The projected 2D points in the image plane.
- Return type:
array of shape (…, 2)
- multicam_calibration.geometry.undistort_points(uvs, camera_matrix, dist_coefs)
Wrapper for cv2.undistortPoints that handles NaNs and batch dimensions.
- Parameters:
uvs (array of shape (..., 2)) – 2D coordinates of points to undistort.
camera_matrix (array of shape (3, 3)) – Camera matrix.
dist_coefs (array of shape (5,)) – Distortion coefficients.
- Returns:
undistorted_uvs – Undistorted 2D coordinates.
- Return type:
array of shape (…, 2)
- multicam_calibration.geometry.triangulate(all_uvs, all_extrinsics, all_intrinsics)
Triangulate 3D points from 2D correspondences.
This function performs robust triangulation by returning the median from all pairs of cameras that observe a given point.
- Parameters:
all_uvs (list of arrays of shape (n_points, 2)) – 2D coordinates of points in the image plane of each camera. Missing points should be represented by NaNs.
all_extrinsics (all_extrinsics : list of arrays of shape (6,)) – Transforms from world to camera coordinates for each camera. The first three elements specify a rotation in axis-angle form and the last three elements specify a translation.
all_intrinsics (list of tuples (camera_matrix, dist_coefs)) – Camera intrinsics for each camera (see
multicam_calibration.get_intrinsics()).
- Returns:
robust_points – Triangulated 3D points. NaNs indicate points that could not be triangulated (because they were observed by fewer than two cameras).
- Return type:
array of shape (n_points, 3)