v3d.CameraSpec#
- class visu3d.CameraSpec(**kwargs)[source]#
Bases:
visu3d.array_dataclass.DataclassArray
Camera intrinsics specification.
Define the interface of camera model. See
PinholeCamera
for an example of class implementation.Support batching to allow to stack multiple cameras with the same resolution in a single
CameraSpec
.specs = dca.stack([PinholeCamera(...) for _ in range(10)]) isinstance(specs, CameraSpec) assert specs.shape == (10,) assert specs.px_centers().shape == (10, h, w, 2)
CameraSpec also allow to project from/to pixel coordinates.
px_coords = specs.px_from_cam @ cam_coords
This works with:
xnp.asarray: (…, 3) -> (…, 2)
Your custom objects. To support this transformation, your dataclass should implement the protocols:
apply_px_from_cam(self, camera_spec: v3d.CameraSpec): to support: spec.px_from_cam @ my_obj
apply_cam_from_px(self, camera_spec: v3d.CameraSpec): to support: spec.cam_from_px @ my_obj
- resolution#
Camera resolution (in px).
- Type:
Tuple[int, int]
- h#
Camera height resolution (in px).
- w#
Camera width resolution (in px).
- fig_config#
Additional figure configuration.
- Type:
visu3d.dc_arrays.camera_spec.TraceConfig
- resolution: Tuple[int, int]#
- fig_config: TraceConfig = TraceConfig( name=None, num_samples=None, scale=1.0, )#
- property h: int#
- property w: int#
- property hw: tuple[int, int]#
(Height, Width) in pixel (for usage in (i, j) coordinates).
- property wh: tuple[int, int]#
(Width, Height) in pixel (for usage in (u, v) coordinates).
- property px_from_cam: visu3d.dc_arrays.transformation.TransformBase#
Project camera 3d coordinates to px 2d coordinates.
Usage:
pts2d = spec.px_from_cam @ pts3d
Input can have arbitrary batch shape, including no batch shape for a single point as input.
- Returns:
The transformation 3d cam coordinates -> 2d pixel coordinates.
- property cam_from_px: visu3d.dc_arrays.transformation.TransformBase#
Unproject 2d pixel coordinates in image space to camera space.
Usage:
pts3d = spec.cam_from_px @ pts2d
Note: Points returned by this function are not normalized. Points are returned at z=1 for pinhole camera.
Input can have arbitrary batch shape, including no batch shape for a single point as input.
- Returns:
The transformation 2d pixel coordinates -> 3d cam coordinates.
- px_centers() etils.enp.array_types.typing.FloatArray [source]#
Returns 2D coordinates of centers of all pixels in the camera image.
This camera model uses the conventions:
Top-left corner of the image is (0, 0)
Bottom-right corner is (w, h) (NOT (h, w))
Pixels are centered, so px_centers()[0, 0] == 0.5
- Returns:
2D image coordinates of center of all pixels of shape (h, w, 2).