Camera Module¶
The camera module provides data structures for representing camera sensors, including intrinsic parameters, distortion models, and captured image data.
Camera¶
- class mimic_data_api.camera.Camera(*, id, name, camera_model, distortion_parameters, extrinsics, trajectory, intrinsics, images_data)[source]¶
Bases:
BaseModelComplete camera sensor representation.
This class encapsulates all information about a camera sensor including its calibration (intrinsic and extrinsic), projection model, trajectory, and captured image data.
- camera_model¶
Projection model type (e.g., “pinhole”, “opencv”, “opencv_fisheye”).
- Type:
CameraModels
- distortion_parameters¶
Lens distortion coefficients for the camera model.
- Type:
- extrinsics¶
4x4 transformation matrix from sensor frame to vehicle frame.
- Type:
SensorExtrinsic
- trajectory¶
Time-series of camera poses in world coordinates.
- Type:
- intrinsics¶
Internal camera parameters (focal length, principal point, image size).
- Type:
- Raises:
ValueError – If image timestamps don’t match trajectory timestamps.
Note
The
images_datatimestamps must exactly match thetrajectory.timestampsarray. This ensures consistent indexing between poses and images.Example
>>> camera = Camera( ... id=0, ... name="front_camera", ... camera_model="pinhole", ... distortion_parameters=DistortionParameters(), ... extrinsics=np.eye(4), ... trajectory=trajectory, ... intrinsics=CameraIntrinsics( ... fx=500, fy=500, cx=320, cy=240, ... skew=0, width=640, height=480 ... ), ... images_data=[ImageData(timestamp=0.0, filepath="img.png", undistorded=True)] ... )
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.
- camera_model: CameraModels¶
- distortion_parameters: DistortionParameters¶
- extrinsics: SensorExtrinsic¶
- trajectory: WorldTrajectory¶
- intrinsics: CameraIntrinsics¶
- validate_images_trajectory_timestamps()[source]¶
Validate that image timestamps match trajectory timestamps.
- Returns:
The validated camera instance.
- Return type:
- Raises:
ValueError – If image timestamps don’t match trajectory timestamps.
- __eq__(other)[source]¶
Check equality with another Camera.
Performs deep comparison of all camera attributes including calibration parameters, trajectory, and image data.
- model_config: ClassVar[ConfigDict] = {}¶
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
Note
Camera.trajectory.object2world contains camera-to-world poses. It is
formed by composing the matching vehicle-to-world pose with
Camera.extrinsics (camera-to-vehicle); it is not the raw ego trajectory.
CameraIntrinsics¶
- class mimic_data_api.camera.CameraIntrinsics(*, fx, fy, cx, cy, skew, height, width)[source]¶
Bases:
BaseModelInternal camera calibration parameters.
This class encapsulates the intrinsic camera matrix parameters that define the projection from 3D camera coordinates to 2D image coordinates.
Note
The intrinsic matrix K is structured as:
\[\begin{split}K = \begin{bmatrix} f_x & skew & c_x \\ 0 & f_y & c_y \\ 0 & 0 & 1 \end{bmatrix}\end{split}\]Example
>>> intrinsics = CameraIntrinsics( ... fx=1000.0, fy=1000.0, ... cx=640.0, cy=360.0, ... skew=0.0, ... width=1280.0, height=720.0 ... ) >>> K = intrinsics.as_K() >>> print(K.shape) (3, 3)
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.
Intrinsic Matrix
The intrinsic matrix K is structured as:
\[\begin{split}K = \begin{bmatrix} f_x & skew & c_x \\ 0 & f_y & c_y \\ 0 & 0 & 1 \end{bmatrix}\end{split}\]- as_K(*, dtype=<class 'numpy.float32'>)[source]¶
Return the 3x3 intrinsic matrix for pinhole-like models.
Constructs the camera calibration matrix K that projects 3D points in camera coordinates to 2D homogeneous image coordinates.
- Parameters:
dtype (numpy.dtype, optional) – Data type for the output array. Default:
np.float32- Returns:
A 3x3 intrinsic calibration matrix K.
- Return type:
Example
>>> intrinsics = CameraIntrinsics( ... fx=500.0, fy=500.0, cx=320.0, cy=240.0, ... skew=0.0, width=640.0, height=480.0 ... ) >>> K = intrinsics.as_K() >>> # Project a 3D point at (1, 0, 5) in camera coordinates >>> point_3d = np.array([1.0, 0.0, 5.0]) >>> point_2d_homogeneous = K @ point_3d >>> point_2d = point_2d_homogeneous[:2] / point_2d_homogeneous[2]
- model_config: ClassVar[ConfigDict] = {}¶
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
DistortionParameters¶
- class mimic_data_api.camera.DistortionParameters(*, p1=0.0, p2=0.0, k1=0.0, k2=0.0, k3=0.0, k4=0.0, k5=None, k6=None, k0=None, p0=None, s0=None, s1=None, s2=None, s3=None, sx1=None, sy1=None, xi=None)[source]¶
Bases:
BaseModelLens distortion coefficients for camera calibration.
This class supports various distortion models including standard OpenCV radial-tangential distortion, fisheye models, and extended models with thin prism distortion.
The distortion is typically applied to normalized image coordinates before projection through the intrinsic matrix.
Note
The standard OpenCV distortion model uses:
\[ \begin{align}\begin{aligned}x_{distorted} = x(1 + k_1 r^2 + k_2 r^4 + k_3 r^6) + 2p_1 xy + p_2(r^2 + 2x^2)\\y_{distorted} = y(1 + k_1 r^2 + k_2 r^4 + k_3 r^6) + p_1(r^2 + 2y^2) + 2p_2 xy\end{aligned}\end{align} \]where \(r^2 = x^2 + y^2\).
Example
>>> distortion = DistortionParameters(k1=-0.1, k2=0.01, p1=0.001, p2=-0.001)
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.
Distortion Model
The standard OpenCV distortion model:
\[x_{distorted} = x(1 + k_1 r^2 + k_2 r^4 + k_3 r^6) + 2p_1 xy + p_2(r^2 + 2x^2)\]\[y_{distorted} = y(1 + k_1 r^2 + k_2 r^4 + k_3 r^6) + p_1(r^2 + 2y^2) + 2p_2 xy\]where \(r^2 = x^2 + y^2\).
- model_config: ClassVar[ConfigDict] = {}¶
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
RollingShutterParameters¶
- class mimic_data_api.camera.RollingShutterParameters(*, readout_time=0.0, readout_direction='global')[source]¶
Bases:
BaseModelRolling shutter timing and direction parameters.
Defines the rolling shutter behavior for cameras that don’t capture all pixels simultaneously. Essential for accurate motion compensation in dynamic scenes.
- readout_time¶
Total time to read out the entire sensor in seconds. A value of 0.0 indicates a global shutter. Default: 0.0
- Type:
- readout_direction¶
Direction in which sensor rows/columns are read out.
"global"indicates simultaneous readout (global shutter). Default:"global"- Type:
{“up_to_down”, “down_to_up”, “left_to_right”, “right_to_left”, “global”}
Note
For rolling shutter cameras, different rows are captured at slightly different times. The time offset for row
ris:\[t_{row} = t_{frame} + \frac{r}{H} \cdot t_{readout}\]where
His the image height and the direction is top-to-bottom.Example
>>> rs = RollingShutterParameters( ... readout_time=0.033, # 33ms readout ... readout_direction="up_to_down" ... )
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.
- readout_direction: Literal['up_to_down', 'down_to_up', 'left_to_right', 'right_to_left', 'global']¶
- model_config: ClassVar[ConfigDict] = {}¶
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
ImageData¶
- class mimic_data_api.camera.ImageData(*, filepath, timestamp, undistorded, rolling_shutter=RollingShutterParameters(readout_time=0.0, readout_direction='global'), image=None, semantic_segmentation_filepath=None, semantic_segmentation_image=None, instance_segmentation_filepath=None, instance_segmentation_image=None, lidar_depth_filepath=None, lidar_depth_image=None, monodepth_filepath=None, monodepth_image=None, normal_filepath=None, normal_segmentation_image=None, wb_params=None, brightness_control=None, dynamic_mask_filepath=None, dynamic_mask_image=None, mask_filepath=None, mask_image=None, vignetting_mask_filepath=None, vignetting_mask_image=None)[source]¶
Bases:
BaseModelMetadata and optional pixel data for a captured camera image.
This class stores information about individual images captured by a camera, including the file location, timestamp, and processing state.
- undistorded¶
Trueif the image has been undistorted (lens distortion removed),Falseif it contains original lens distortion.- Type:
- rolling_shutter¶
Rolling shutter parameters for this specific image. Default: global shutter (no rolling shutter effect).
- Type:
- image¶
Optional in-memory image data. Not serialized to JSON.
- Type:
RGBImage or None
- Raises:
ValueError – If filepath doesn’t end with .png, .jpg, or .jpeg.
Example
>>> img_data = ImageData( ... filepath="data/images/frame_000.png", ... timestamp=0.0, ... undistorded=False ... )
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.
- rolling_shutter: RollingShutterParameters¶
- classmethod validate_filepath(v)[source]¶
Validate that the filepath has a supported image extension.
- Parameters:
v (str) – The filepath to validate.
- Returns:
The validated filepath.
- Return type:
- Raises:
ValueError – If the filepath doesn’t end with a supported extension.
- model_config: ClassVar[ConfigDict] = {}¶
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
Camera Models¶
- mimic_data_api.camera.CameraModels¶
Supported camera projection models (aligned with COLMAP):
simple_pinhole: Single focal length (fx = fy), no distortionpinhole: Separate fx, fy, no distortionsimple_radial: Single focal length with k1 distortionradial: Single focal length with k1, k2 distortionopencv: Full OpenCV model (fx, fy, cx, cy, k1, k2, p1, p2)opencv_fisheye: OpenCV fisheye modelequirectangular: 360° equirectangular projectionomnidirectionalstereo_l: ODS left eyeomnidirectionalstereo_r: ODS right eyevr180_l: VR180 left eyevr180_r: VR180 right eyeorthophoto: Orthographic projectionfisheye624: 6+2+4 parameter fisheye model
See COLMAP Camera Models for detailed documentation.