Skip to content

typing

CameraDistortionLike = Union[CameraDistortion, ArrayLike, Sequence[float], list[float]] module-attribute

Type alias for camera distortion inputs.

Accepts
  • CameraDistortion instances
  • NumPy arrays with shape (5,)
  • Sequence of float values

CameraIntrinsicLike = Union[CameraIntrinsic, ArrayLike, Sequence[Sequence[float]], list[list[float]]] module-attribute

Type alias for camera parameter inputs.

Accepts
  • CameraIntrinsic instances
  • NumPy arrays with shape (3, 3)
  • Nested sequences of float values

Matrix3x3Like = Union[Matrix3x3, ArrayLike, Sequence[Sequence[float]], list[list[float]]] module-attribute

Type alias for 3x3 matrix inputs.

Accepts
  • NumPy arrays with shape (3, 3)
  • Nested lists: [[a, b, c], [d, e, f], [g, h, i]]
  • Any nested sequence representing a 3x3 matrix

Matrix4x4Like = Union[Matrix4x4, ArrayLike, Sequence[Sequence[float]], list[list[float]]] module-attribute

Type alias for 4x4 matrix inputs.

Accepts
  • NumPy arrays with shape (4, 4)
  • Nested lists: 4x4 structure
  • Any nested sequence representing a 4x4 matrix

PointLike = Union[Vector2Like, Vector3Like] module-attribute

Type alias for single point inputs (2D or 3D).

PointsLike = Union[ArrayLike, Sequence[Sequence[float]], list[list[float]], list[tuple[float, ...]]] module-attribute

Type alias for multiple points inputs.

Accepts
  • NumPy arrays with shape (N, 2) or (N, 3)
  • Lists of lists: [[x1, y1], [x2, y2], ...]
  • Lists of tuples: [(x1, y1), (x2, y2), ...]
  • Any nested sequence representing multiple points

QuaternionLike = Union[Quaternion, ArrayLike, Sequence[float], tuple[float, float, float, float], list[float]] module-attribute

Type alias for quaternion inputs.

Accepts
  • Quaternion instances
  • NumPy arrays with shape (4,) - [w, x, y, z]
  • Lists: [w, x, y, z]
  • Tuples: (w, x, y, z)
  • Any sequence with 4 float elements representing quaternion components

RoiLike = Union[Roi, ArrayLike, Sequence[float], tuple[float, float, float, float], list[float]] module-attribute

Type alias for Region of Interest (ROI) inputs.

Accepts
  • Roi instances
  • NumPy arrays with shape (4,)
  • Lists: [xmin, ymin, xmax, ymax]
  • Tuples: (xmin, ymin, xmax, ymax)
  • Any sequence with 4 float elements representing bounding box coordinates

RotationLike = Union[QuaternionLike, ArrayLike] module-attribute

Type alias for general rotation inputs.

Accepts
  • All QuaternionLike inputs
  • 3x3 rotation matrices as NumPy arrays
  • Any array-like object representing rotations

ScalarLike = Union[int, float, np.number] module-attribute

Type alias for scalar numeric inputs.

Accepts
  • Python int or float
  • NumPy scalar types

TrajectoryLike = Union[ArrayLike, Sequence[Sequence[Sequence[float]]], list[list[list[float]]]] module-attribute

Type alias for trajectory inputs.

Accepts
  • NumPy arrays with shape (M, T, D) where:
  • M = number of modes
  • T = number of timesteps
  • D = spatial dimensions (usually 3)
  • Triple-nested sequences with same structure

Vector2Like = Union[Vector2, ArrayLike, Sequence[float], tuple[float, float], list[float]] module-attribute

Type alias for 2D vector inputs.

Accepts
  • Vector2 instances
  • NumPy arrays with shape (2,)
  • Lists: [x, y]
  • Tuples: (x, y)
  • Any sequence with 2 float elements

Vector3Like = Union[Vector3, ArrayLike, Sequence[float], tuple[float, float, float], list[float]] module-attribute

Type alias for 3D vector inputs.

Accepts
  • Vector3 instances
  • NumPy arrays with shape (3,)
  • Lists: [x, y, z]
  • Tuples: (x, y, z)
  • Any sequence with 3 float elements

Vector6Like = Union[Vector6, ArrayLike, Sequence[float], tuple[float, ...], list[float]] module-attribute

Type alias for 6D vector inputs.

Accepts
  • Vector6 instances
  • NumPy arrays with shape (6,)
  • Lists: [x1, x2, x3, x4, x5, x6]
  • Tuples: (x1, x2, x3, x4, x5, x6)
  • Any sequence with 6 float elements

CameraDistortion

Bases: ndarray

A 1D array representing camera lens distortion coefficients.

This class represents the distortion parameters for a camera lens following the OpenCV distortion model. It supports arrays of length 4, 5, 8, 12, or 14 elements, corresponding to different distortion models.

The distortion coefficients follow the OpenCV convention: (k1, k2, p1, p2[, k3[, k4, k5, k6[, s1, s2, s3, s4[, τx, τy]]]])

Coefficient meanings
  • k1, k2, k3, k4, k5, k6: Radial distortion coefficients
  • p1, p2: Tangential distortion coefficients
  • s1, s2, s3, s4: Thin prism distortion coefficients
  • τx, τy: Tilted sensor distortion coefficients
Supported array lengths
  • 4 elements: (k1, k2, p1, p2) - Basic radial and tangential
  • 5 elements: (k1, k2, p1, p2, k3) - Extended radial distortion
  • 8 elements: (k1, k2, p1, p2, k3, k4, k5, k6) - Rational model
  • 12 elements: (k1, k2, p1, p2, k3, k4, k5, k6, s1, s2, s3, s4) - With thin prism
  • 14 elements: (k1, k2, p1, p2, k3, k4, k5, k6, s1, s2, s3, s4, τx, τy) - Full model

Note that for non-camera, the array can be empty.

Examples:

>>> d = CameraDistortion([0, 0, 0, 0])                     # 4 elements: basic model
>>> d = CameraDistortion([0, 0, 0, 0, 0])                  # 5 elements: with k3
>>> d = CameraDistortion([1, 2, 3, 4, 5])                  # 5 elements: valid coefficients
>>> d = CameraDistortion([1, 2, 3, 4, 5, 6, 7, 8])         # 8 elements: rational model
>>> d = CameraDistortion([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12])  # 12 elements: with thin prism
>>> d = CameraDistortion([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14])  # 14 elements: full model
>>> d = CameraDistortion([])                               # Empty array for non-camera
>>> d = CameraDistortion([1, 2, 3])                        # ValueError: invalid length
>>> d = CameraDistortion([1, 2, 3, 4, 5, 6])               # ValueError: invalid length
Source code in t4_devkit/typing/camera.py
class CameraDistortion(np.ndarray):
    """A 1D array representing camera lens distortion coefficients.

    This class represents the distortion parameters for a camera lens following
    the OpenCV distortion model. It supports arrays of length 4, 5, 8, 12, or 14
    elements, corresponding to different distortion models.

    The distortion coefficients follow the OpenCV convention:
    (k1, k2, p1, p2[, k3[, k4, k5, k6[, s1, s2, s3, s4[, τx, τy]]]])

    Coefficient meanings:
        - k1, k2, k3, k4, k5, k6: Radial distortion coefficients
        - p1, p2: Tangential distortion coefficients
        - s1, s2, s3, s4: Thin prism distortion coefficients
        - τx, τy: Tilted sensor distortion coefficients

    Supported array lengths:
        - 4 elements: (k1, k2, p1, p2) - Basic radial and tangential
        - 5 elements: (k1, k2, p1, p2, k3) - Extended radial distortion
        - 8 elements: (k1, k2, p1, p2, k3, k4, k5, k6) - Rational model
        - 12 elements: (k1, k2, p1, p2, k3, k4, k5, k6, s1, s2, s3, s4) - With thin prism
        - 14 elements: (k1, k2, p1, p2, k3, k4, k5, k6, s1, s2, s3, s4, τx, τy) - Full model

    Note that for non-camera, the array can be empty.

    Examples:
        >>> d = CameraDistortion([0, 0, 0, 0])                     # 4 elements: basic model
        >>> d = CameraDistortion([0, 0, 0, 0, 0])                  # 5 elements: with k3
        >>> d = CameraDistortion([1, 2, 3, 4, 5])                  # 5 elements: valid coefficients
        >>> d = CameraDistortion([1, 2, 3, 4, 5, 6, 7, 8])         # 8 elements: rational model
        >>> d = CameraDistortion([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12])  # 12 elements: with thin prism
        >>> d = CameraDistortion([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14])  # 14 elements: full model
        >>> d = CameraDistortion([])                               # Empty array for non-camera
        >>> d = CameraDistortion([1, 2, 3])                        # ValueError: invalid length
        >>> d = CameraDistortion([1, 2, 3, 4, 5, 6])               # ValueError: invalid length
    """

    def __new__(cls, input_array: ArrayLike) -> CameraDistortion:
        obj = np.array(input_array).view(cls)

        # skip validation if the array is empty for non-camera
        if obj.size == 0:
            return obj

        # validate the shape of the array
        # OpenCV supports distortion coefficient arrays of length 4, 5, 8, 12, or 14
        valid_lengths = (4, 5, 8, 12, 14)
        if obj.ndim != 1 or obj.shape[0] not in valid_lengths:
            raise ValueError(
                f"CameraDistortion must be a 1D array of length {valid_lengths}, got: {obj.shape}"
            )

        return obj

CameraIntrinsic

Bases: ndarray

A 3x3 camera intrinsic matrix with validation.

This class ensures that the input array is a 3x3 matrix and raises a ValueError if it is not. It can be constructed from a 3x3 array or 9 elements array.

Note that for non-camera, the array can be empty.

Examples:

>>> i = CameraIntrinsic(np.eye(3))                          # OK
>>> i = CameraIntrinsic([1, 0, 0, 0, 1, 0, 0, 0, 1])        # OK
>>> i = CameraIntrinsic([[1, 0, 0], [0, 1, 0], [0, 0, 1]])  # OK
>>> i = CameraIntrinsic([])                                 # OK
>>> i = CameraIntrinsic(np.eye(2))                          # ValueError
>>> i = CameraIntrinsic([1, 0, 0, 0, 1, 0, 0, 0])           # ValueError
Source code in t4_devkit/typing/camera.py
class CameraIntrinsic(np.ndarray):
    """A 3x3 camera intrinsic matrix with validation.

    This class ensures that the input array is a 3x3 matrix and raises a ValueError if it is not.
    It can be constructed from a 3x3 array or 9 elements array.

    Note that for non-camera, the array can be empty.

    Examples:
        >>> i = CameraIntrinsic(np.eye(3))                          # OK
        >>> i = CameraIntrinsic([1, 0, 0, 0, 1, 0, 0, 0, 1])        # OK
        >>> i = CameraIntrinsic([[1, 0, 0], [0, 1, 0], [0, 0, 1]])  # OK
        >>> i = CameraIntrinsic([])                                 # OK
        >>> i = CameraIntrinsic(np.eye(2))                          # ValueError
        >>> i = CameraIntrinsic([1, 0, 0, 0, 1, 0, 0, 0])           # ValueError
    """

    def __new__(cls, input_array: ArrayLike) -> CameraIntrinsic:
        obj = np.array(input_array).view(cls)

        # skip validation if the array is empty for non-camera
        if obj.size == 0:
            return obj

        if obj.ndim == 1 and obj.shape == (9,):
            obj = obj.reshape((3, 3))

        # validate the shape of the array
        if obj.shape != (3, 3):
            raise ValueError(f"CameraIntrinsic must be a 3x3 array, got: {obj.shape}")

        return obj

Matrix3x3

Bases: ndarray

A 3x3 matrix with validation.

Examples:

>>> matrix = Matrix3x3([[1, 2, 3], [4, 5, 6], [7, 8, 9]])   # OK
>>> matrix = Matrix3x3(np.eye(3))                           # OK
>>> matrix = Matrix3x3([[1, 2], [4, 5], [7, 8]])            # ValueError
>>> matrix = Matrix3x3(np.eye(2))                           # ValueError
Source code in t4_devkit/typing/matrix.py
class Matrix3x3(np.ndarray):
    """A 3x3 matrix with validation.

    Examples:
        >>> matrix = Matrix3x3([[1, 2, 3], [4, 5, 6], [7, 8, 9]])   # OK
        >>> matrix = Matrix3x3(np.eye(3))                           # OK
        >>> matrix = Matrix3x3([[1, 2], [4, 5], [7, 8]])            # ValueError
        >>> matrix = Matrix3x3(np.eye(2))                           # ValueError
    """

    def __new__(cls, input_array: ArrayLike) -> Matrix3x3:
        obj = np.array(input_array).view(cls)
        if obj.shape != (3, 3):
            raise ValueError(f"Input array must be of shape (3, 3), got: {obj.shape}")
        return obj

Matrix4x4

Bases: ndarray

A 4x4 matrix with validation.

Examples:

>>> matrix = Matrix4x4([[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12], [13, 14, 15, 16]]) # OK
>>> matrix = Matrix4x4(np.eye(4))                                                       # OK
>>> matrix = Matrix4x4([[1, 2], [4, 5], [7, 8]])                                        # ValueError
>>> matrix = Matrix4x4(np.eye(2))                                                       # ValueError
Source code in t4_devkit/typing/matrix.py
class Matrix4x4(np.ndarray):
    """A 4x4 matrix with validation.

    Examples:
        >>> matrix = Matrix4x4([[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12], [13, 14, 15, 16]]) # OK
        >>> matrix = Matrix4x4(np.eye(4))                                                       # OK
        >>> matrix = Matrix4x4([[1, 2], [4, 5], [7, 8]])                                        # ValueError
        >>> matrix = Matrix4x4(np.eye(2))                                                       # ValueError
    """

    def __new__(cls, input_array: ArrayLike) -> Matrix4x4:
        obj = np.array(input_array).view(cls)
        if obj.shape != (4, 4):
            raise ValueError(f"Input array must be of shape (4, 4), got: {obj.shape}")
        return obj

Quaternion

Bases: Quaternion

A quaternion class that wraps the PyQuaternion class.

This wrapper exists to provide a consistent and explicit quaternion representation.

Examples:

>>> q = Quaternion(1, 2, 3, 4)
>>> q
Quaternion(1.000000, 2.000000, 3.000000, 4.000000)
>>> q.conjugate()
Quaternion(1.000000, -2.000000, -3.000000, -4.000000)
>>> q.norm()
5.477226
>>> q.inverse()
Quaternion(0.181818, -0.363636, -0.545455, -0.727273)
>>> q * q.inverse()
Quaternion(1.000000, 0.000000, 0.000000, 0.000000)
Source code in t4_devkit/typing/quaternion.py
class Quaternion(PyQuaternion):
    """A quaternion class that wraps the PyQuaternion class.

    This wrapper exists to provide a consistent and explicit quaternion representation.

    Examples:
        >>> q = Quaternion(1, 2, 3, 4)
        >>> q
        Quaternion(1.000000, 2.000000, 3.000000, 4.000000)
        >>> q.conjugate()
        Quaternion(1.000000, -2.000000, -3.000000, -4.000000)
        >>> q.norm()
        5.477226
        >>> q.inverse()
        Quaternion(0.181818, -0.363636, -0.545455, -0.727273)
        >>> q * q.inverse()
        Quaternion(1.000000, 0.000000, 0.000000, 0.000000)
    """

    pass

Roi

Bases: tuple

A 4-element tuple representing a region of interest (ROI).

This class ensures that the array always has the correct shape and value order. It can be constructed from any array-like object that can be converted to a tuple of length 4, or from individual numeric arguments.

Examples:

>>> roi = Roi(10, 20, 30, 40)   # OK
>>> roi = Roi((10, 20, 30, 40)) # OK
>>> roi = Roi([10, 20, 30, 40]) # OK
>>> roi = Roi([10, 20])         # ValueError: ROI must be 4-elements
>>> roi = Roi([40, 30, 20, 10]) # ValueError: ROI must be xmin <= xmax && ymin <= ymax
Source code in t4_devkit/typing/roi.py
class Roi(tuple):
    """A 4-element tuple representing a region of interest (ROI).

    This class ensures that the array always has the correct shape and value order.
    It can be constructed from any array-like object that can be converted to a tuple of length 4,
    or from individual numeric arguments.

    Examples:
        >>> roi = Roi(10, 20, 30, 40)   # OK
        >>> roi = Roi((10, 20, 30, 40)) # OK
        >>> roi = Roi([10, 20, 30, 40]) # OK
        >>> roi = Roi([10, 20])         # ValueError: ROI must be 4-elements
        >>> roi = Roi([40, 30, 20, 10]) # ValueError: ROI must be xmin <= xmax && ymin <= ymax
    """

    def __new__(cls, *args: Any) -> Roi:
        """Create a new Roi instance.

        Args:
            *args: Either a single array-like object with 4 elements, or 4 individual numeric values.

        Returns:
            Roi instance.

        Raises:
            ValueError: If the input is not 4 elements or if the values are not in the correct order.
        """
        # Handle different input formats
        if len(args) == 1:
            # Single argument - should be an iterable
            try:
                input_array = tuple(args[0])
            except TypeError:
                # Not iterable, treat as single value
                input_array = args
        elif len(args) == 4:
            # Four individual arguments
            input_array = args
        else:
            # Wrong number of arguments
            input_array = args

        # validate input shape of the array
        if len(input_array) != 4:
            raise ValueError(f"ROI must be a 4-element tuple, got: {input_array}")

        # validate input value order of the array
        xmin, ymin, xmax, ymax = input_array
        if xmax < xmin or ymax < ymin:
            raise ValueError(
                f"ROI must be (xmin, ymin, xmax, ymax) and xmin <= xmax && ymin <= ymax, got: {input_array}"
            )

        return super().__new__(cls, input_array)

    @property
    def offset(self) -> tuple[ScalarLike, ScalarLike]:
        """Return the xy offset from the image origin at the top left corner."""
        xmin, ymin, *_ = self
        return xmin, ymin

    @property
    def size(self) -> tuple[ScalarLike, ScalarLike]:
        """Return the width and height of the ROI."""
        xmin, ymin, xmax, ymax = self
        return xmax - xmin, ymax - ymin

    @property
    def width(self) -> ScalarLike:
        """Return the width of the ROI."""
        return self.size[0]

    @property
    def height(self) -> ScalarLike:
        """Return the height of the ROI."""
        return self.size[1]

    @property
    def center(self) -> tuple[ScalarLike, ScalarLike]:
        """Return the center position of the ROI."""
        xmin, ymin, xmax, ymax = self
        return (xmin + xmax) / 2, (ymin + ymax) / 2

    @property
    def area(self) -> ScalarLike:
        """Return the area of the ROI."""
        return self.width * self.height

area property

Return the area of the ROI.

center property

Return the center position of the ROI.

height property

Return the height of the ROI.

offset property

Return the xy offset from the image origin at the top left corner.

size property

Return the width and height of the ROI.

width property

Return the width of the ROI.

__new__(*args)

Create a new Roi instance.

Parameters:

Name Type Description Default
*args Any

Either a single array-like object with 4 elements, or 4 individual numeric values.

()

Returns:

Type Description
Roi

Roi instance.

Raises:

Type Description
ValueError

If the input is not 4 elements or if the values are not in the correct order.

Source code in t4_devkit/typing/roi.py
def __new__(cls, *args: Any) -> Roi:
    """Create a new Roi instance.

    Args:
        *args: Either a single array-like object with 4 elements, or 4 individual numeric values.

    Returns:
        Roi instance.

    Raises:
        ValueError: If the input is not 4 elements or if the values are not in the correct order.
    """
    # Handle different input formats
    if len(args) == 1:
        # Single argument - should be an iterable
        try:
            input_array = tuple(args[0])
        except TypeError:
            # Not iterable, treat as single value
            input_array = args
    elif len(args) == 4:
        # Four individual arguments
        input_array = args
    else:
        # Wrong number of arguments
        input_array = args

    # validate input shape of the array
    if len(input_array) != 4:
        raise ValueError(f"ROI must be a 4-element tuple, got: {input_array}")

    # validate input value order of the array
    xmin, ymin, xmax, ymax = input_array
    if xmax < xmin or ymax < ymin:
        raise ValueError(
            f"ROI must be (xmin, ymin, xmax, ymax) and xmin <= xmax && ymin <= ymax, got: {input_array}"
        )

    return super().__new__(cls, input_array)

Vector2

Bases: BaseVector

A 2-element numpy array with validation.

This class ensures that the array always has exactly 2 elements. It can be constructed from any array-like object that can be converted to a 2-element numpy array.

Examples:

>>> v = Vector2([1, 2])             # OK
>>> v = Vector2(np.array([1, 2]))   # OK
>>> v = Vector2(1, 2)               # OK
>>> v = Vector2([1, 2, 3])          # ValueError
Source code in t4_devkit/typing/vector.py
class Vector2(BaseVector):
    """A 2-element numpy array with validation.

    This class ensures that the array always has exactly 2 elements.
    It can be constructed from any array-like object that can be converted
    to a 2-element numpy array.

    Examples:
        >>> v = Vector2([1, 2])             # OK
        >>> v = Vector2(np.array([1, 2]))   # OK
        >>> v = Vector2(1, 2)               # OK
        >>> v = Vector2([1, 2, 3])          # ValueError
    """

    _expected_shape = (2,)

Vector3

Bases: BaseVector

A 3-element numpy array with validation.

This class ensures that the array always has exactly 3 elements. It can be constructed from any array-like object that can be converted to a 3-element numpy array.

Examples:

>>> v = Vector3([1, 2, 3])              # OK
>>> v = Vector3(np.array([1, 2, 3]))    # OK
>>> v = Vector3(1, 2, 3)                # OK
>>> v = Vector3([1, 2])                 # ValueError
Source code in t4_devkit/typing/vector.py
class Vector3(BaseVector):
    """A 3-element numpy array with validation.

    This class ensures that the array always has exactly 3 elements.
    It can be constructed from any array-like object that can be converted
    to a 3-element numpy array.

    Examples:
        >>> v = Vector3([1, 2, 3])              # OK
        >>> v = Vector3(np.array([1, 2, 3]))    # OK
        >>> v = Vector3(1, 2, 3)                # OK
        >>> v = Vector3([1, 2])                 # ValueError
    """

    _expected_shape = (3,)

Vector6

Bases: BaseVector

A 6-element numpy array with validation.

This class ensures that the array always has exactly 6 elements. It can be constructed from any array-like object that can be converted to a 6-element numpy array.

Examples:

>>> v = Vector6([1, 2, 3, 4, 5, 6])             # OK
>>> v = Vector6(np.array([1, 2, 3, 4, 5, 6]))   # OK
>>> v = Vector6(1, 2, 3, 4, 5, 6)               # OK
>>> v = Vector6([1, 2])                         # ValueError
Source code in t4_devkit/typing/vector.py
class Vector6(BaseVector):
    """A 6-element numpy array with validation.

    This class ensures that the array always has exactly 6 elements.
    It can be constructed from any array-like object that can be converted
    to a 6-element numpy array.

    Examples:
        >>> v = Vector6([1, 2, 3, 4, 5, 6])             # OK
        >>> v = Vector6(np.array([1, 2, 3, 4, 5, 6]))   # OK
        >>> v = Vector6(1, 2, 3, 4, 5, 6)               # OK
        >>> v = Vector6([1, 2])                         # ValueError
    """

    _expected_shape = (6,)