SkewIntrinsic Class#
Overview#
- class SkewIntrinsic(parameters=None, constants=None)[source]#
Subclass of the
pycvcam.core.Intrinsicclass that represents the OpenCV intrinsic model with skew parameter.Note
This class represents the intrinsic transformation, which is the last step of the process from the
world_pointsto theimage_points.Let \(\vec{x}_d = (x_d, y_d)\) be a point in distorted normalized camera coordinates. The corresponding image point \(\vec{x}_i = (x_i, y_i)\) is obtained using the intrinsic matrix \(K\):
\[\vec{x}_i = K \vec{x}_d\]where the intrinsic matrix is defined as
\[\begin{split}K = \begin{bmatrix} f_x & s & c_x \\ 0 & f_y & c_y \\ 0 & 0 & 1 \end{bmatrix}\end{split}\]with
\(f_x, f_y\) the focal lengths expressed in pixels,
\(c_x, c_y\) the principal point coordinates in pixels,
\(s\) the skew parameter.
Note
If no distortion model is used, the distorted coordinates \(\vec{x}_d\) are identical to the normalized coordinates \(\vec{x}_n\).
The transformation is parameterized by 5 parameters and 0 constants:
focal length parameters \((f_x, f_y)\)
principal point parameters \((c_x, c_y)\)
skew parameter \(s\)
Two shorthand views of the Jacobian matrix are available in the result object:
jacobian_df: Jacobian of the image points with respect to the focal lengths. Shape(..., 2, 2)corresponding to \((f_x, f_y)\).jacobian_dc: Jacobian of the image points with respect to the principal point. Shape(..., 2, 2)corresponding to \((c_x, c_y)\).jacobian_ds: Jacobian of the image points with respect to the skew parameter. Shape(..., 2, 1)corresponding to \(s\).
Note
The class can be instantiated in two ways:
providing the parameters directly as a numpy array of shape
(5,)containing(f_x, f_y, c_x, c_y, s),using the
from_matrix()class method to initialize the transformation from an intrinsic matrix.
- Parameters:
parameters (Optional[ArrayLike]) – Intrinsic parameters of shape
(5,)ordered as(f_x, f_y, c_x, c_y, s).constants (Optional[None])
Instantiation#
The pycvcam.SkewIntrinsic class can be instantiated in two ways:
From a 3×3 intrinsic matrix using the classmethod
from_matrix().From a parameter vector using the classmethod
from_vector().
|
Class method to create a SkewIntrinsic object from an intrinsic matrix. |
|
Class method to create a SkewIntrinsic object from an intrinsic vector. |
Accessing Parameters#
The intrinsic parameters and constants can be accessed via the base class
pycvcam.core.Transform:
parameters: returns a vector of intrinsic parameters [f_x, f_y, c_x, c_y, s].constants: returns any constants (none for SkewIntrinsic).
Convenience properties are provided for direct access:
[Get/Set] the focal length |
|
[Get/Set] the focal length |
|
[Get/Set] the principal point |
|
[Get/Set] the principal point |
|
[Get/Set] the skew parameter |
|
Get or set the intrinsic matrix of the intrinsic transformation. |
|
Get or set the intrinsic vector of the intrinsic transformation. |
Performing Projections#
Use the transform and inverse_transform methods from
pycvcam.core.Transform to perform intrinsic projections:
transform: mapsdistorted_points→image_points.inverse_transform: mapsimage_points→distorted_points.
Jacobians with respect to the input points and intrinsic parameters
can be computed by enabling the dx and dp flags:
dx=True: compute ∂image_points / ∂distorted_pointsdp=True: compute ∂image_points / ∂intrinsic_parameters
|
Apply the intrinsic projection from distorted normalized coordinates to image pixel coordinates. |
|
Apply the inverse of the intrinsic projection from image pixel coordinates to distorted normalized coordinates. |
Examples#
Create an intrinsic object from a matrix:
import numpy
from pycvcam import SkewIntrinsic
intrinsic_matrix = numpy.array([[1000, 0.5, 320],
[0, 1000, 240],
[0, 0, 1]])
intrinsic = SkewIntrinsic.from_matrix(intrinsic_matrix)
Transform distorted points to image points:
distorted_points = numpy.array([[100, 200],
[150, 250],
[200, 300]])
# Forward projection
result = intrinsic.transform(distorted_points)
image_points = result.image_points
print("Image points:\n", image_points)
Compute Jacobians:
result = intrinsic.transform(distorted_points, dx=True, dp=True)
jacobian_dx = result.jacobian_dx
jacobian_dp = result.jacobian_dp
print("Jacobian w.r.t input points:\n", jacobian_dx)
print("Jacobian w.r.t intrinsic parameters:\n", jacobian_dp)
Inverse transformation:
inverse_result = intrinsic.inverse_transform(image_points, dx=True, dp=True)
recovered_distorted = inverse_result.distorted_points
print("Recovered distorted points:\n", recovered_distorted)