Skip to content

pixano.features.schemas.annotations.camcalibration

BaseIntrinsics

Bases: BaseType

BaseIntrinsics (TODO: description?).

Attributes:

Name Type Description
cx_offset_px float

cx_offset_px

cy_offset_px float

cy_offset_px

img_height_px int

img_height_px

img_width_px int

img_width_px

CamCalibration(created_at=None, updated_at=None, **data)

Bases: Annotation

Camera calibration.

Attributes:

Name Type Description
type str

Type of camera.

base_intrinsics BaseIntrinsics

Base intrinsics values.

extrinsics Extrinsics

Extrinsics values.

intrinsics Intrinsics

Intrinsics values.

Source code in pixano/features/schemas/base_schema.py
def __init__(self, /, created_at: datetime | None = None, updated_at: datetime | None = None, **data: Any):
    """Create a new model by parsing and validating input data from keyword arguments.

    Raises [`ValidationError`][pydantic_core.ValidationError] if the input data cannot be
    validated to form a valid model.

    `self` is explicitly positional-only to allow `self` as a field name.

    Args:
        created_at: The creation date of the object.
        updated_at: The last modification date of the object.
        data: The data of the object validated by Pydantic.
    """
    created_at, updated_at = validate_and_init_create_at_and_update_at(created_at, updated_at)
    data.update({"created_at": created_at, "updated_at": updated_at})
    super().__init__(**data)

none() classmethod

Utility function to get a None equivalent. Should be removed as soon as Lance manages None value.

Returns:

Type Description
Self

"None" CamCalibration.

Source code in pixano/features/schemas/annotations/camcalibration.py
@classmethod
def none(cls) -> Self:
    """Utility function to get a `None` equivalent.
    Should be removed as soon as Lance manages `None` value.

    Returns:
        "None" `CamCalibration`.
    """
    return cls(
        id="",
        item_ref=ItemRef.none(),
        view_ref=ViewRef.none(),
        entity_ref=EntityRef.none(),
        type="",
        base_intrinsics=BaseIntrinsics(
            cx_offset_px=0.0,
            cy_offset_px=0.0,
            img_height_px=0,
            img_width_px=0,
        ),
        extrinsics=Extrinsics(
            pos_x_m=0.0,
            pos_y_m=0.0,
            pos_z_m=0.0,
            rot_x_deg=0.0,
            rot_z1_deg=0.0,
            rot_z2_deg=0.0,
        ),
        intrinsics=Intrinsics(
            c1=0.0,
            c2=0.0,
            c3=0.0,
            c4=0.0,
            pixel_aspect_ratio=0.0,
        ),
    )

Extrinsics

Bases: BaseType

Extrinsics (TODO: description?).

Attributes:

Name Type Description
pos_x_m float

pos_x_m.

pos_y_m float

pos_y_m.

pos_z_m float

pos_z_m.

rot_x_deg float

rot_x_deg.

rot_z1_deg float

rot_z1_deg.

rot_z2_deg float

rot_z2_deg.

Intrinsics

Bases: BaseType

Intrinsics (TODO: description?).

Attributes:

Name Type Description
c1 float

c1.

c2 float

c2.

c3 float

c3.

c4 float

c4.

pixel_aspect_ratio float

pixel_aspect_ratio.

create_cam_calibration(type, base_intrinsics=None, extrinsics=None, intrinsics=None, cx_offset_px=None, cy_offset_px=None, img_height_px=None, img_width_px=None, pos_x_m=None, pos_y_m=None, pos_z_m=None, rot_x_deg=None, rot_z1_deg=None, rot_z2_deg=None, c1=None, c2=None, c3=None, c4=None, pixel_aspect_ratio=None, id='', item_ref=ItemRef.none(), view_ref=ViewRef.none(), entity_ref=EntityRef.none(), source_ref=SourceRef.none(), validate=True)

Create a CamCalibration instance.

Parameters:

Name Type Description Default
type str

The type of camera.

required
base_intrinsics BaseIntrinsics | None

The base intrinsics.

None
extrinsics Extrinsics | None

The extrinsics.

None
intrinsics Intrinsics | None

The intrinsics.

None
cx_offset_px float | None

cx_offset_px.

None
cy_offset_px float | None

cy_offset_px.

None
img_height_px int | None

img_height_px.

None
img_width_px int | None

img_width_px.

None
pos_x_m float | None

pos_x_m.

None
pos_y_m float | None

pos_y_m.

None
pos_z_m float | None

pos_z_m.

None
rot_x_deg float | None

rot_x_deg.

None
rot_z1_deg float | None

rot_z1_deg.

None
rot_z2_deg float | None

rot_z2_deg.

None
c1 float | None

c1.

None
c2 float | None

c2.

None
c3 float | None

c3.

None
c4 float | None

c4.

None
pixel_aspect_ratio float | None

pixel_aspect_ratio.

None
id str

CamCalibration ID.

''
item_ref ItemRef

Item reference.

none()
view_ref ViewRef

View reference.

none()
entity_ref EntityRef

Entity reference.

none()
source_ref SourceRef

Source reference.

none()
validate bool

Set to False to skip pydantic validation.

True

Returns:

Type Description
CamCalibration

The created CamCalibration instance.

Source code in pixano/features/schemas/annotations/camcalibration.py
def create_cam_calibration(
    type: str,
    base_intrinsics: BaseIntrinsics | None = None,
    extrinsics: Extrinsics | None = None,
    intrinsics: Intrinsics | None = None,
    cx_offset_px: float | None = None,
    cy_offset_px: float | None = None,
    img_height_px: int | None = None,
    img_width_px: int | None = None,
    pos_x_m: float | None = None,
    pos_y_m: float | None = None,
    pos_z_m: float | None = None,
    rot_x_deg: float | None = None,
    rot_z1_deg: float | None = None,
    rot_z2_deg: float | None = None,
    c1: float | None = None,
    c2: float | None = None,
    c3: float | None = None,
    c4: float | None = None,
    pixel_aspect_ratio: float | None = None,
    id: str = "",
    item_ref: ItemRef = ItemRef.none(),
    view_ref: ViewRef = ViewRef.none(),
    entity_ref: EntityRef = EntityRef.none(),
    source_ref: SourceRef = SourceRef.none(),
    validate: bool = True,
) -> CamCalibration:
    """Create a `CamCalibration` instance.

    Args:
        type: The type of camera.
        base_intrinsics: The base intrinsics.
        extrinsics: The extrinsics.
        intrinsics: The intrinsics.
        cx_offset_px: cx_offset_px.
        cy_offset_px: cy_offset_px.
        img_height_px: img_height_px.
        img_width_px: img_width_px.
        pos_x_m: pos_x_m.
        pos_y_m: pos_y_m.
        pos_z_m: pos_z_m.
        rot_x_deg: rot_x_deg.
        rot_z1_deg: rot_z1_deg.
        rot_z2_deg: rot_z2_deg.
        c1: c1.
        c2: c2.
        c3: c3.
        c4: c4.
        pixel_aspect_ratio: pixel_aspect_ratio.
        id: `CamCalibration` ID.
        item_ref: Item reference.
        view_ref: View reference.
        entity_ref: Entity reference.
        source_ref: Source reference.
        validate: Set to False to skip pydantic validation.

    Returns:
        The created `CamCalibration` instance.
    """
    none_obj_conditions = [
        base_intrinsics is None,
        extrinsics is None,
        intrinsics is None,
    ]
    not_none_obj_conditions = [
        base_intrinsics is not None,
        extrinsics is not None,
        intrinsics is not None,
    ]

    none_field_conditions = [
        cx_offset_px is None,
        cy_offset_px is None,
        img_height_px is None,
        img_width_px is None,
        pos_x_m is None,
        pos_y_m is None,
        pos_z_m is None,
        rot_x_deg is None,
        rot_z1_deg is None,
        rot_z2_deg is None,
        c1 is None,
        c2 is None,
        c3 is None,
        c4 is None,
        pixel_aspect_ratio is None,
    ]

    not_none_field_conditions = [
        cx_offset_px is not None,
        cy_offset_px is not None,
        img_height_px is not None,
        img_width_px is not None,
        pos_x_m is not None,
        pos_y_m is not None,
        pos_z_m is not None,
        rot_x_deg is not None,
        rot_z1_deg is not None,
        rot_z2_deg is not None,
        c1 is not None,
        c2 is not None,
        c3 is not None,
        c4 is not None,
        pixel_aspect_ratio is not None,
    ]

    if not all(none_obj_conditions) and not all(not_none_obj_conditions):
        raise ValueError("base_intrinsics, extrinsics and intrinsics must be all defined or all None")
    elif not all(none_field_conditions) and not all(not_none_field_conditions):
        raise ValueError(
            "cx_offset_px, cy_offset_px, img_height_px, img_width_px, pos_x_m, pos_y_m, pos_z_m, "
            "rot_x_deg, rot_z1_deg, rot_z2_deg, c1, c2, c3, c4 and pixel_aspect_ratio must be all "
            "defined or all None"
        )
    elif any(not_none_obj_conditions) and any(not_none_field_conditions):
        raise ValueError(
            "base_intrinsics, extrinsics and intrinsics must defined or cx_offset_px, cy_offset_px, img_height_px, "
            "img_width_px, pos_x_m, pos_y_m, pos_z_m, rot_x_deg, rot_z1_deg, rot_z2_deg, c1, c2, c3, c4 and "
            "pixel_aspect_ratio must be defined but not both"
        )
    if any(not_none_field_conditions):
        if validate:
            base_intrinsics = BaseIntrinsics(
                cx_offset_px=cx_offset_px,
                cy_offset_px=cy_offset_px,
                img_height_px=img_height_px,
                img_width_px=img_width_px,
            )
            extrinsics = Extrinsics(
                pos_x_m=pos_x_m,
                pos_y_m=pos_y_m,
                pos_z_m=pos_z_m,
                rot_x_deg=rot_x_deg,
                rot_z1_deg=rot_z1_deg,
                rot_z2_deg=rot_z2_deg,
            )
            intrinsics = Intrinsics(
                c1=c1,
                c2=c2,
                c3=c3,
                c4=c4,
                pixel_aspect_ratio=pixel_aspect_ratio,
            )
        else:
            base_intrinsics = BaseIntrinsics.construct(
                cx_offset_px=cx_offset_px,
                cy_offset_px=cy_offset_px,
                img_height_px=img_height_px,
                img_width_px=img_width_px,
            )
            extrinsics = Extrinsics.construct(
                pos_x_m=pos_x_m,
                pos_y_m=pos_y_m,
                pos_z_m=pos_z_m,
                rot_x_deg=rot_x_deg,
                rot_z1_deg=rot_z1_deg,
                rot_z2_deg=rot_z2_deg,
            )
            intrinsics = Intrinsics.construct(
                c1=c1,
                c2=c2,
                c3=c3,
                c4=c4,
                pixel_aspect_ratio=pixel_aspect_ratio,
            )

    if validate:
        return CamCalibration(
            type=type,
            base_intrinsics=base_intrinsics,
            extrinsics=extrinsics,
            intrinsics=intrinsics,
            id=id,
            item_ref=item_ref,
            view_ref=view_ref,
            entity_ref=entity_ref,
            source_ref=source_ref,
        )
    else:
        return CamCalibration.construct(
            type=type,
            base_intrinsics=base_intrinsics,
            extrinsics=extrinsics,
            intrinsics=intrinsics,
            id=id,
            item_ref=item_ref,
            view_ref=view_ref,
            entity_ref=entity_ref,
            source_ref=source_ref,
        )

is_cam_calibration(cls, strict=False)

Check if a class is a CamCalibration or subclass of CamCalibration.

Source code in pixano/features/schemas/annotations/camcalibration.py
def is_cam_calibration(cls: type, strict: bool = False) -> bool:
    """Check if a class is a `CamCalibration` or subclass of `CamCalibration`."""
    return issubclass_strict(cls, CamCalibration, strict)