OrthographicExtrinsic Class#
Overview#
- class OrthographicExtrinsic(parameters=None, constants=None)[source]#
Subclass of
pycvcam.Extrinsicimplementing the orthographic extrinsic camera model.This class represents the extrinsic transformation, which is the first step in the camera projection pipeline from
world_pointstoimage_points. The transformation maps points from the world coordinate system to the normalized camera coordinate system.Mathematically, given a 3D point in world coordinates:
\[\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.
\(T\) is a 3×1 translation vector.
The normalized coordinates are then obtained by orthographic projection:
\[\vec{x}_n = (X_c, Y_c)\]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.
- Parameters:
parameters (Optional[ArrayLike]) – The extrinsic parameters as a 1D array of shape (6,). The first 3 elements represent the rotation vector \(\vec{rvec} = (r_x, r_y, r_z)\). The last 3 elements represent the translation vector \(\vec{tvec} = (t_x, t_y, t_z)\).
constants (Optional[None])
Constants#
This model has 0 constants.
Jacobians#
The following convenient aliases are provided in the transformation result:
jacobian_dr: Jacobian of normalized points with respect to the rotation vector. Shape (…, 2, 3).jacobian_dt: Jacobian of normalized points with respect to the translation vector. Shape (…, 2, 3).
Notes
The transformation is fully characterized by 6 parameters (rotation + translation).
Normalized points are always 2D, obtained after orthographic projection.
Instantiate#
The pycvcam.OrthographicExtrinsic class can be instantiated using :
a rotation and translation vector (
rvec,tvec).a \(4 \times 4\) transformation matrix.
a frame of reference associated with the extrinsic parameters.
Class method to create a OrthographicExtrinsic object from a 3D frame. |
|
|
Class method to create a OrthographicExtrinsic object from a rotation vector and a translation vector. |
|
Class method to create a OrthographicExtrinsic object from a 4x4 transformation matrix. |
Accessing Parameters#
The extrinsic parameters and constants can be accessed via the base class
pycvcam.Transform:
parameters: returns a vector of extrinsic parameters [rvec, tvec].constants: returns any constants (empty for OrthographicExtrinsic).
Convenience properties are provided for direct access:
[Get/Set] the 3D frame of the extrinsic transformation. |
|
[Get/Set] the rotation vector |
|
[Get/Set] the 4x4 transformation matrix of the extrinsic transformation. |
|
[Get/Set] the translation vector |
Performing Projections#
Use the transform and inverse_transform methods from
pycvcam.Transform to perform extrinsic projections:
transform: mapsworld_points→normalized_points.inverse_transform: mapsnormalized_points→world_points.
Jacobians with respect to the input points and extrinsic parameters
can be computed by enabling the dx and dp flags:
dx=True: compute ∂normalized_points / ∂world_pointsdp=True: compute ∂normalized_points / ∂extrinsic_parameters
|
Compute the transformation from 3D world points to 2D normalized camera points. |
Compute the inverse transformation from 2D normalized camera points to 3D world points. |
|
Compute the 3D rays from the camera to the scene in world coordinates. |
Examples#
Create an extrinsic object with a rotation vector and a translation vector:
import numpy
from pycvcam import OrthographicExtrinsic
rvec = numpy.array([0.1, 0.2, 0.3])
tvec = numpy.array([0.5, 0.5, 0.5])
extrinsic = OrthographicExtrinsic.from_rt(rvec, tvec)
Then you can use the extrinsic object to transform world_points to normalized_points:
world_points = numpy.array([[1, 2, 3],
[4, 5, 6],
[7, 8, 9],
[10, 11, 12]]) # shape (n_points, 3)
result = extrinsic.transform(world_points)
normalized_points = result.normalized_points # shape (n_points, 2)
print(normalized_points)
You can also access to the jacobian of the extrinsic transformation:
result = extrinsic.transform(world_points, dx=True, dp=True)
normalized_points_dx = result.jacobian_dx # Shape (n_points, 2, 3)
normalized_points_dp = result.jacobian_dp # Shape (n_points, 2, 6)
print(normalized_points_dx)
print(normalized_points_dp)
The inverse transformation can be computed using the inverse_transform method: By default, the depth is assumed to be 1.0 for all points, but you can provide a specific depth for each point with shape (…,).
depth = numpy.array([1.0, 2.0, 3.0, 4.0]) # Example depth values for each point
inverse_result = extrinsic.inverse_transform(normalized_points, dx=True, dp=True, depth=depth)
world_points = inverse_result.world_points # Shape (n_points, 3)
print(world_points)
Note
The jacobian with respect to the depth is not computed.