Pinhole Camera

Pinhole Metadata

class py123d.datatypes.PinholeCameraMetadata[source]

Static metadata for a pinhole camera, stored in a log.

Public Data Attributes:

camera_model

The projection model of this camera.

camera_name

The name of the pinhole camera, according to the dataset naming convention.

camera_id

The CameraID of the pinhole camera.

intrinsics

The PinholeIntrinsics of the pinhole camera.

distortion

The PinholeDistortion of the pinhole camera.

width

The image width in pixels.

height

The image height in pixels.

camera_to_imu_se3

The camera-to-IMU extrinsic PoseSE3 of the pinhole camera.

is_undistorted

Whether the camera images are already undistorted.

is_distorted

Whether the camera images are distorted.

fov_x

The horizontal field of view (FOV) of the pinhole camera in radians, if available.

fov_y

The vertical field of view (FOV) of the pinhole camera in radians, if available.

Inherited from BaseCameraMetadata

camera_model

The projection model of the camera.

camera_id

The camera ID, unique within a sensor rig.

camera_name

The camera name, according to the dataset naming convention.

camera_to_imu_se3

The static extrinsic pose of the camera relative to the IMU frame.

width

The width of the camera image in pixels.

height

The height of the camera image in pixels.

channel_type

The channel type of the camera image.

modality_type

Returns the type of the modality that this metadata describes.

modality_id

Returns the camera ID as the modality ID.

aspect_ratio

The aspect ratio (width / height) of the camera.

Inherited from BaseModalityMetadata

modality_type

Returns the type of the modality that this metadata describes.

modality_id

Optional identifier for the modality, e.g. sensor ID for sensor modalities.

modality_key

Returns a unique key for this modality, combining type and id if applicable.

Public Methods:

from_dict(data_dict)

Create a PinholeCameraMetadata from a dictionary.

to_dict()

Converts the PinholeCameraMetadata to a dictionary.

project_to_image(points_cam)

Project 3D points in camera frame to image pixel coordinates using the pinhole model.

Inherited from BaseCameraMetadata

project_to_image(points_cam)

Project 3D points in camera frame to image pixel coordinates.

Inherited from BaseMetadata

to_dict()

Serialize the metadata instance to a plain Python dictionary.

from_dict(data_dict)

Construct a metadata instance from a plain Python dictionary.

Private Methods:

Inherited from BaseCameraMetadata

_compute_in_fov_mask(pixel_coords, depth[, eps])

Compute a boolean mask for points in front of the camera and within image bounds.


classmethod from_dict(data_dict)[source]

Create a PinholeCameraMetadata from a dictionary.

Parameters:

data_dict (Dict[str, Any]) – A dictionary containing the metadata.

Return type:

PinholeCameraMetadata

Returns:

A PinholeCameraMetadata instance.

to_dict()[source]

Converts the PinholeCameraMetadata to a dictionary.

Return type:

Dict[str, Any]

Returns:

A dictionary representation of the PinholeCameraMetadata instance, with default Python types.

property camera_model: CameraModel

The projection model of this camera.

property camera_name: str

The name of the pinhole camera, according to the dataset naming convention.

property camera_id: CameraID

The CameraID of the pinhole camera.

property aspect_ratio: float

The aspect ratio (width / height) of the camera.

property channel_type: CameraChannelType

The channel type of the camera image. Defaults to RGB.

property intrinsics: PinholeIntrinsics | None

The PinholeIntrinsics of the pinhole camera.

property modality_id: str | SerialIntEnum | None

Returns the camera ID as the modality ID.

property modality_key: str

Returns a unique key for this modality, combining type and id if applicable.

property modality_type: ModalityType

Returns the type of the modality that this metadata describes.

property distortion: PinholeDistortion | None

The PinholeDistortion of the pinhole camera.

property width: int

The image width in pixels.

property height: int

The image height in pixels.

property camera_to_imu_se3: PoseSE3

The camera-to-IMU extrinsic PoseSE3 of the pinhole camera.

property is_undistorted: bool

Whether the camera images are already undistorted.

property is_distorted: bool

Whether the camera images are distorted.

project_to_image(points_cam)[source]

Project 3D points in camera frame to image pixel coordinates using the pinhole model.

If the camera has distortion parameters and images are not pre-undistorted, the OpenCV radial-tangential distortion model is applied so that projected pixels match the raw (distorted) image.

Parameters:

points_cam (ndarray[tuple[Any, ...], dtype[float64]]) – (N, 3) array of 3D points in the camera coordinate frame.

Return type:

Tuple[ndarray[tuple[Any, ...], dtype[float64]], ndarray[tuple[Any, ...], dtype[bool]], ndarray[tuple[Any, ...], dtype[float64]]]

Returns:

A tuple of (pixel_coords (N,2), in_fov_mask (N,), depth (N,)).

Raises:

ValueError – If intrinsics are not set.

property fov_x: float | None

The horizontal field of view (FOV) of the pinhole camera in radians, if available.

property fov_y: float | None

The vertical field of view (FOV) of the pinhole camera in radians, if available.

Pinhole Intrinsics

class py123d.datatypes.PinholeIntrinsics[source]

Pinhole camera intrinsics representation.

Public Data Attributes:

array

A numpy array representation of the pinhole intrinsics, indexed by PinholeIntrinsicsIndex.

fx

Focal length in x direction.

fy

Focal length in y direction.

cx

Optical center x coordinate.

cy

Optical center y coordinate.

skew

Skew coefficient.

camera_matrix

The 3x3 camera intrinsic matrix K.

Inherited from ArrayMixin

array

The array representation of the geometric entity.

shape

Return the shape of the array.

Public Methods:

from_array(array[, copy])

Creates a PinholeIntrinsics from a numpy array, indexed by PinholeIntrinsicsIndex.

from_camera_matrix(intrinsic)

Create a PinholeIntrinsics from a 3x3 intrinsic matrix.

Inherited from ArrayMixin

from_array(array[, copy])

Create an instance from a NumPy array.

from_list(values)

Create an instance from a list of values.

tolist()

Convert the array to a Python list.

to_list()

Convert the array to a Python list.

copy()

Return a copy of the object with a copied array.


classmethod from_array(array, copy=True)[source]

Creates a PinholeIntrinsics from a numpy array, indexed by PinholeIntrinsicsIndex.

Parameters:
  • array (ndarray[tuple[Any, ...], dtype[float64]]) – A 1D numpy array containing the intrinsic parameters.

  • copy (bool) – Whether to copy the array, defaults to True

Return type:

PinholeIntrinsics

Returns:

A PinholeIntrinsics instance.

classmethod from_camera_matrix(intrinsic)[source]

Create a PinholeIntrinsics from a 3x3 intrinsic matrix.

Parameters:

intrinsic (ndarray[tuple[Any, ...], dtype[float64]]) – A 3x3 numpy array representing the intrinsic matrix.

Return type:

PinholeIntrinsics

Returns:

A PinholeIntrinsics instance.

property array: ndarray[tuple[Any, ...], dtype[float64]]

A numpy array representation of the pinhole intrinsics, indexed by PinholeIntrinsicsIndex.

property fx: float

Focal length in x direction.

property fy: float

Focal length in y direction.

property cx: float

Optical center x coordinate.

property cy: float

Optical center y coordinate.

property skew: float

Skew coefficient. Not used in most cases.

property camera_matrix: ndarray[tuple[Any, ...], dtype[float64]]

The 3x3 camera intrinsic matrix K.

Pinhole Distortion

class py123d.datatypes.PinholeDistortion[source]

Pinhole camera distortion representation.

Public Data Attributes:

array

A numpy array representation of the pinhole distortion, indexed by PinholeDistortionIndex.

k1

Radial distortion coefficient k1.

k2

Radial distortion coefficient k2.

p1

Tangential distortion coefficient p1.

p2

Tangential distortion coefficient p2.

k3

Radial distortion coefficient k3.

Inherited from ArrayMixin

array

The array representation of the geometric entity.

shape

Return the shape of the array.

Public Methods:

from_array(array[, copy])

Creates a PinholeDistortion from a numpy array, indexed by PinholeDistortionIndex.

Inherited from ArrayMixin

from_array(array[, copy])

Create an instance from a NumPy array.

from_list(values)

Create an instance from a list of values.

tolist()

Convert the array to a Python list.

to_list()

Convert the array to a Python list.

copy()

Return a copy of the object with a copied array.


classmethod from_array(array, copy=True)[source]

Creates a PinholeDistortion from a numpy array, indexed by PinholeDistortionIndex.

Parameters:
  • array (ndarray[tuple[Any, ...], dtype[float64]]) – A 1D numpy array containing the distortion parameters.

  • copy (bool) – Whether to copy the array, defaults to True

Return type:

PinholeDistortion

Returns:

A PinholeDistortion instance.

property array: ndarray[tuple[Any, ...], dtype[float64]]

A numpy array representation of the pinhole distortion, indexed by PinholeDistortionIndex.

property k1: float

Radial distortion coefficient k1.

property k2: float

Radial distortion coefficient k2.

property p1: float

Tangential distortion coefficient p1.

property p2: float

Tangential distortion coefficient p2.

property k3: float

Radial distortion coefficient k3.