pycvcam.SkewIntrinsic#
SkewIntrinsic Class#
- class SkewIntrinsic(parameters=None, constants=None)[source]#
Subclass of the
pycvcam.core.Intrinsicclass that represents the OpenCV intrinsic model with an additional skew parameter.Note
This class represents the intrinsic transformation, which is the last step of the process from the
world_pointsto theimage_points.The
SkewIntrinsicmodel used an intrinsic matrix to transform thedistorted_pointsto theimage_points.The equation used for the intrinsic transformation is:
\[\begin{split}\begin{align*} \vec{x}_i &= K \cdot \vec{x}_d \\ \end{align*}\end{split}\]where \(\vec{x}_d\) is the distorted points, \(\vec{x}_i\) is the image points, and \(K\) is the intrinsic matrix defined as:
\[\begin{split}K = \begin{bmatrix} f_x & s & c_x \\ 0 & f_y & c_y \\ 0 & 0 & 1 \end{bmatrix}\end{split}\]where \(f_x\) and \(f_y\) are the focal lengths in pixels in x and y direction, \(c_x\) and \(c_y\) are the principal point coordinates in pixels in x and y direction, and \(s\) is the skew parameter.
Note
If no distortion is applied, the
distorted_pointsare equal to thenormalized_points.This transformation is caracterized by 5 parameters and 0 constants:
2 parameters as focal length \(\vec{f} = (f_x, f_y)\).
2 parameters as principal point \(\vec{c} = (c_x, c_y)\).
1 parameter as skew \(s\).
Two short-hand notations are provided to access the jacobian with respect to the focal length and principal point in the results class:
jacobian_df: The Jacobian of the image points with respect to the focal length parameters. It has shape (…, 2, 2), where the last dimension represents (df_x, df_y).jacobian_dc: The Jacobian of the image points with respect to the principal point parameters. It has shape (…, 2, 2), where the last dimension represents (dc_x, dc_y).jacobian_ds: The Jacobian of the image points with respect to the skew parameter. It has shape (…, 2, 1), where the last dimension represents (ds).
Note
The
SkewIntrinsicclass can be instantiated with 2 different ways:Setting directly the parameters as a numpy array of shape (5,) (__init__ method) containing the focal length, principal point, and skew concatenated.
Using the classmethod
from_matrixto set the intrinsic matrix.
- Parameters:
parameters (Optional[numpy.ndarray]) – The parameters of the intrinsic transformation. It should be a numpy array of shape (5,) containing the focal length, principal point, and skew concatenated.
constants (Optional[numpy.ndarray])
Instantiate a SkewIntrinsic object#
The pycvcam.SkewIntrinsic class can be instantiated using :
a \(3 \times 3\) intrinsic matrix.
|
Class method to create a SkewIntrinsic object from an intrinsic matrix. |
Accessing the parameters of SkewIntrinsic objects#
The parameters and constants properties can be accessing using pycvcam.core.Transform methods.
Some additional convenience methods are provided to access commonly used parameters of the SkewIntrinsic model:
Get or set the focal length |
|
Get or set the focal length |
|
Get or set the intrinsic matrix of the intrinsic transformation. |
|
Get or set the intrinsic vector of the intrinsic transformation. |
|
Get or set the principal point |
|
Get or set the principal point |
|
Get or set the skew parameter |
Performing projections with SkewIntrinsic objects#
The transform and inverse_transform methods can be used to perform intrinsic transformations using the SkewIntrinsic model (as described in the pycvcam.core.Transform documentation).
The implementation of theses transformations and more details on the options available can be found in the following methods:
|
Compute the transformation from the |
|
Compute the inverse transformation from the |
Examples#
Create an intrinsic object with a given intrinsic matrix:
import numpy
from pycvcam import SkewIntrinsic
intrinsic_matrix = numpy.array([[1000, 5, 320],
[0, 1000, 240],
[0, 0, 1]])
intrinsic = SkewIntrinsic.from_matrix(intrinsic_matrix)
Then you can use the intrinsic object to transform distorted_points to image_points:
distorted_points = numpy.array([[100, 200],
[150, 250],
[200, 300]]) # Shape (n_points, 2)
result = intrinsic.transform(distorted_points)
image_points = result.image_points # Shape (n_points, 2)
print(image_points)
You can also access to the jacobian of the intrinsic transformation:
result = intrinsic.transform(distorted_points, dx=True, dp=True)
image_points_dx = result.jacobian_dx # Jacobian of the image points with respect to the distorted points
image_points_dp = result.jacobian_dp # Jacobian of the image points with respect to the intrinsic parameters
print(image_points_dx)
The inverse transformation can be computed using the inverse_transform method:
inverse_result = intrinsic.inverse_transform(image_points, dx=True, dp=True)
distorted_points = inverse_result.distorted_points # Shape (n_points, 2)
print(distorted_points)
See also
For more information about the transformation process, see:
pycvcam.SkewIntrinsic._transform()to transform thedistorted_pointstoimage_points.pycvcam.SkewIntrinsic._inverse_transform()to transform theimage_pointsback todistorted_points.