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:
pysdic.PerspectiveExtrinsic: perspective projection \((X_c / Z_c, \ Y_c / Z_c)\) (pinhole camera);pysdic.OrthographicExtrinsic: orthographic projection \((X_c, \ Y_c)\) (telecentric lens).
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:
TransformationAbstract 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:
pysdic.PerspectiveExtrinsic: perspective division \(\vec{x}_n = (X_c / Z_c, Y_c / Z_c)\).pysdic.OrthographicExtrinsic: orthographic projection \(\vec{x}_n = (X_c, Y_c)\).
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
depthargument ofinvert.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 apy3dframe.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
_applyand_invert(with adepthkeyword argument) and the methodcompute_rays. The helper_rotation_and_derivativescan be used to get the rotation matrix with its derivatives, andpysdic._validation._as_scalar_or_1d_arrayto validate the depth.Note
The rigid extrinsics require OpenCV (
cv2, forcv2.Rodrigues): anImportErroris raised at the instantiation if it is missing. Theframeaccessors also requirepy3dframe, 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:
- property frame: py3dframe.Frame | None#
[Get/Set] the 3D frame of the extrinsic transformation.
The frame is a
py3dframe.Frameobject 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:
- 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:
- 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:
- 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:
- 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:
- 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:
- 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_matrixisrmatto 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_vectorisrvecto match OpenCV conventions.Note
The rotation vector can only be set if all the parameters are already set.
See also
translation_vector()ortvecto get the translation vector of the camera.
- 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_matrixistmatrix.- 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_vectoristvecto match OpenCV conventions.Note
The translation vector can only be set if all the parameters are already set.
See also
rotation_vector()orrvecto get the rotation vector of the camera.
- 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
PerspectiveExtrinsic and OrthographicExtrinsic for the two implementations.
PlanarRigidExtrinsic and the
WorldPlane*Extrinsicfor the extrinsics of a plane.