pysdic.RigidExtrinsic#

The pysdic.RigidExtrinsic is the common base of the extrinsic transformations made of a rigid motion of the world points into the frame of the camera, \(\vec{X}_c = R \, \vec{X} + \vec{t}\), followed by a projection onto the normalized plane:

The rotation \(R\) and the translation \(\vec{t}\) (world to camera, OpenCV convention) are the parameters of the transformation.

RigidExtrinsic class#

class RigidExtrinsic(*args, **kwargs)[source]#

Bases: Transformation

Abstract base class of the extrinsic camera models based on a rigid motion of the world points into the camera coordinate system, followed by a projection onto the normalized camera plane.

This class represents an extrinsic transformation, which is typically the first step in the camera projection pipeline:

world_points → normalized_points → distorted_points → image_points

Given a world point \(\vec{X}_w = (X_w, Y_w, Z_w)^T\), the corresponding point in the camera coordinate system is:

\[\vec{X}_c = R \cdot \vec{X}_w + T\]

where:

  • \(R\) is a 3×3 rotation matrix, parameterized by a rotation vector \(\vec{r}\) (Rodrigues form).

  • \(T\) is a 3×1 translation vector.

The transformation is parameterized by 6 parameters \((r_x, r_y, r_z, t_x, t_y, t_z)\). The projection of the camera points \(\vec{X}_c\) onto the normalized points \(\vec{x}_n\) is defined by the subclasses:

Since the depth is lost by the projection, the inverse transformation needs the depth \(Z_c\) of the points in the camera coordinate system, given with the depth argument of invert.

Note

To compute the rotation matrix or vector:

  • Use cv2.Rodrigues() to convert between rotation vectors and matrices.

  • Or use py3dframe.Frame (convention 4) for consistent 3D frame handling.

See also

py3dframe for frame and rotation vector utilities.

Note

The subclasses can be instantiated in four ways:

  • providing the parameters directly as a numpy array of shape (6,).

  • using the from_rt() class method with a rotation vector and a translation vector.

  • using the from_tmatrix() class method with a 4x4 transformation matrix.

  • using the from_frame() class method with a py3dframe.Frame.

Parameters:

parameters (Optional[ArrayLike], optional (default: None)) – The extrinsic parameters as a 1D array of shape (6,). The first 3 elements represent the rotation vector \(\vec{r} = (r_x, r_y, r_z)\). The last 3 elements represent the translation vector \(T = (t_x, t_y, t_z)\).

Implementation details#

The subclasses must set the capability flags and implement the projection with the methods _apply and _invert (with a depth keyword argument) and the method compute_rays. The helper _rotation_and_derivatives can be used to get the rotation matrix with its derivatives, and pysdic._validation._as_scalar_or_1d_array to validate the depth.

Note

The rigid extrinsics require OpenCV (cv2, for cv2.Rodrigues): an ImportError is raised at the instantiation if it is missing. The frame accessors also require py3dframe, which is only imported when they are used.

abstractmethod compute_rays(normalized_points)[source]#

Compute the rays of the camera passing through the given normalized points.

Parameters:

normalized_points (ArrayLike) – Normalized points in the camera coordinate system. Shape (..., 2).

Returns:

Rays in world coordinates with shape (..., 6) (same batch shape as the input points), where the last dimension encodes the ray origin (x, y, z) and the unit direction (dx, dy, dz).

Return type:

pysdic.Rays

property frame: py3dframe.Frame | None#

[Get/Set] the 3D frame of the extrinsic transformation.

The frame is a py3dframe.Frame object representing the 3D frame of the camera in the world coordinate system (convention 4).

See also

Artezaru/py3dframe for more information about the Frame class.

Parameters:

frame (Optional[py3dframe.Frame]) – The 3D frame of the camera in the world coordinate system, or None to unset the parameters.

Returns:

The 3D frame of the camera in the world coordinate system. (or None if the parameters are not set)

Return type:

Optional[py3dframe.Frame]

classmethod from_frame(frame)[source]#

Create an extrinsic transformation from a 3D frame (convention 4).

The returned object is an instance of the class on which the method is called.

Parameters:

frame (py3dframe.Frame) – The 3D frame of the camera in the world coordinate system.

Returns:

A new instance of the class with the specified 3D frame.

Return type:

pysdic.RigidExtrinsic

classmethod from_rt(rvec, tvec)[source]#

Create an extrinsic transformation from a rotation vector and a translation vector.

The returned object is an instance of the class on which the method is called.

Parameters:
  • rvec (ArrayLike) – The rotation vector of the camera in Rodrigues form with shape (3,).

  • tvec (ArrayLike) – The translation vector of the camera with shape (3,).

Returns:

A new instance of the class with the specified rotation and translation vectors.

Return type:

pysdic.RigidExtrinsic

classmethod from_tmatrix(tmatrix)[source]#

Create an extrinsic transformation from a 4x4 transformation matrix.

The returned object is an instance of the class on which the method is called.

Parameters:

tmatrix (ArrayLike) – The 4x4 transformation matrix of the camera with shape (4, 4).

Returns:

A new instance of the class with the specified transformation matrix.

Return type:

pysdic.RigidExtrinsic

property input_dim: int#

[Get] the input dimension of the extrinsic transformation (3D world points).

Returns:

The input dimension of the extrinsic transformation.

Return type:

int

property n_parameters: int#

[Get] the number of parameters of the extrinsic transformation (always 6).

Returns:

The number of parameters of the extrinsic transformation.

Return type:

int

property output_dim: int#

[Get] the output dimension of the extrinsic transformation (2D normalized points).

Returns:

The output dimension of the extrinsic transformation.

Return type:

int

property parameter_names: List[str]#

[Get] the names of the parameters of the extrinsic transformation: ["rx", "ry", "rz", "tx", "ty", "tz"].

Returns:

The names of the parameters of the extrinsic transformation.

Return type:

List[str]

property rotation_matrix: ndarray | None#

[Get/Set] the rotation matrix \(R\) of the extrinsic transformation.

The rotation matrix is a numpy array of shape (3, 3) computed from the rotation vector with cv2.Rodrigues.

Note

An alias for rotation_matrix is rmat to match OpenCV conventions.

Note

The rotation matrix can only be set if all the parameters are already set.

Parameters:

rmat (ArrayLike) – The rotation matrix of the camera with shape (3, 3). It must be orthonormal with a determinant equal to +1.

Returns:

The rotation matrix of the camera with shape (3, 3). (or None if the parameters are not set)

Return type:

Optional[numpy.ndarray]

property rotation_vector: ndarray | None#

[Get/Set] the rotation vector \(\vec{r}\) of the camera.

The rotation vector is a numpy array of shape (3,) representing the rotation of the camera in Rodrigues form. It corresponds to the first three parameters of the extrinsic transformation.

Note

An alias for rotation_vector is rvec to match OpenCV conventions.

Note

The rotation vector can only be set if all the parameters are already set.

See also

Parameters:

rvec (ArrayLike) – The rotation vector of the camera in Rodrigues form with shape (3,).

Returns:

The rotation vector of the camera with shape (3,). (or None if the parameters are not set)

Return type:

Optional[numpy.ndarray]

property transformation_matrix: ndarray | None#

[Get/Set] the 4x4 transformation matrix of the extrinsic transformation.

\[\begin{split}\begin{bmatrix} R & T \\ 0 & 1 \end{bmatrix}\end{split}\]

Note

An alias for transformation_matrix is tmatrix.

Parameters:

tmatrix (Optional[ArrayLike]) – The 4x4 transformation matrix of the camera, or None to unset the parameters.

Returns:

The 4x4 transformation matrix of the camera. (or None if the parameters are not set)

Return type:

Optional[numpy.ndarray]

property translation_vector: ndarray | None#

[Get/Set] the translation vector \(T\) of the camera.

The translation vector is a numpy array of shape (3,). It corresponds to the last three parameters of the extrinsic transformation.

Note

An alias for translation_vector is tvec to match OpenCV conventions.

Note

The translation vector can only be set if all the parameters are already set.

See also

Parameters:

tvec (ArrayLike) – The translation vector of the camera with shape (3,).

Returns:

The translation vector of the camera with shape (3,). (or None if the parameters are not set)

Return type:

Optional[numpy.ndarray]

See also