Skip to content

StereoCalibration ​

SUMMARY

Left and right camera intrinsics plus the rigid transform and baseline between their optical frames, with optional color-camera calibration.

python
import numpy as np

from telekinesis import datatypes

camera = datatypes.CameraCalibration(
    width=1280,
    height=720,
    distortion_model="plumb_bob",
    distortion_parameters=[-0.2, 0.1, 0.0, 0.0, 0.0],
    intrinsic_matrix=[1000.0, 0.0, 640.0, 0.0, 1000.0, 360.0, 0.0, 0.0, 1.0],
)
left_to_right = np.eye(4, dtype=np.float32)
left_to_right[0, 3] = 0.12
calibration = datatypes.StereoCalibration(camera, camera, left_to_right)
API Reference
Complete API documentation for StereoCalibration, including parameters, attributes, and methods.
View Reference →

Parameters ​

ParameterTypeDefaultDescription
leftCameraCalibrationRequiredCalibration for the left camera.
rightCameraCalibrationRequiredCalibration for the right camera.
left_to_rightMat4x4 | Transform3D | np.ndarrayRequiredHomogeneous rigid transform from the left optical frame to the right optical frame.
colorCameraCalibration | NoneNoneOptional calibration for a third color camera.
left_to_colorMat4x4 | Transform3D | np.ndarray | NoneNoneOptional rigid transform from the left optical frame to the color optical frame; required exactly when color is provided.

Coordinates and translation values are expressed in metres.

Raises ​

ExceptionCondition
TypeErrorA camera calibration or transform uses an unsupported representation.
ValueErrorA transform is non-finite, has an invalid homogeneous bottom row, contains a non-orthonormal or improper rotation, or color and left_to_color are not provided together.

Attributes ​

AttributeTypeDescription
leftCameraCalibrationIndependent value containing the left-camera calibration.
rightCameraCalibrationIndependent value containing the right-camera calibration.
left_to_rightMat4x4Independent left-to-right optical-frame transform.
colorCameraCalibration | NoneIndependent optional color-camera calibration.
left_to_colorMat4x4 | NoneIndependent optional left-to-color transform.
baselinefloatEuclidean translation distance between the left and right optical frames, in metres.

Calibration and transform inputs are stored independently, and the accessors return independent values.

Methods ​

MethodReturnsDescription
StereoCalibration.coerce(value)StereoCalibrationReturns an existing instance or constructs one from a dictionary of constructor fields.
copy()StereoCalibrationReturns an independent copy of the stereo calibration.

Operators ​

OperationBehavior
calibration == otherCompares both camera calibrations and all transforms by semantic value.
repr(calibration)Shows the baseline and whether color-camera calibration is present.

Example ​

python
"""Demonstrates the Telekinesis StereoCalibration datatype."""

import time

import numpy as np
from loguru import logger

from telekinesis import datatypes


def stereo_calibration_example():
    """Demonstrate creation, inspection, operations, and serialization."""

    # ======================= Create ============================================
    camera = datatypes.CameraCalibration(
        width=1280,
        height=720,
        distortion_model="plumb_bob",
        distortion_parameters=[-0.2, 0.1, 0.0, 0.0, 0.0],
        intrinsic_matrix=[1000.0, 0.0, 640.0, 0.0, 1000.0, 360.0, 0.0, 0.0, 1.0],
    )
    left_to_right = np.eye(4, dtype=np.float32)
    left_to_right[0, 3] = 0.12
    calibration = datatypes.StereoCalibration(
        left=camera,
        right=camera,
        left_to_right=datatypes.Mat4x4(left_to_right),
    )
    logger.info(f"Created StereoCalibration: {calibration}")

    # ======================= Inspect ===========================================
    logger.info(f"left calibration: {calibration.left}")
    logger.info(f"right calibration: {calibration.right}")
    logger.info(f"left-to-right transform:\n{calibration.left_to_right.to_numpy()}")
    logger.info(f"baseline={calibration.baseline:.3f} m")

    # ======================= Operations ========================================
    transform_copy = calibration.left_to_right
    transform_copy.data = np.eye(4, dtype=np.float32)
    logger.info(
        "Mutating the returned transform does not affect the calibration: "
        f"baseline={calibration.baseline:.3f} m"
    )

    # ======================= Serialize / Deserialize ===========================
    start = time.perf_counter()
    serialized = datatypes.serialize(calibration)
    serialization_ms = (time.perf_counter() - start) * 1000

    start = time.perf_counter()
    deserialized = datatypes.deserialize(serialized)["param_0"]
    deserialization_ms = (time.perf_counter() - start) * 1000

    logger.info(f"Deserialized StereoCalibration: {deserialized}")
    logger.info(f"Round-trip successful: {calibration == deserialized}")
    logger.info(f"Serialization time: {serialization_ms:.3f} ms")
    logger.info(f"Deserialization time: {deserialization_ms:.3f} ms")


if __name__ == "__main__":
    stereo_calibration_example()