py123d_detection.torch.data.cameras

Reading a rig’s images for one frame, already in network geometry.

Per camera: compose the rig’s fixed crop with the sample’s resize, crop and flip into one affine map, decode the image, resample it once through the map, and move the intrinsics by the same map. Calibration and image size come from the log’s camera metadata, which is rig-static in 123D, so the map is known before any pixel is decoded.

That lets the decoder do the first part of a large reduction. When the network input is at most half the sensor resolution, the image is decoded at 1/2, 1/4 or 1/8 size, for JPEG in the DCT domain. That is several times faster than a full decode and a proper low-pass filter, where a bilinear warp over a 2x reduction samples single pixels and aliases.

Images stay uint8. Normalisation is the model’s job, on the device; see normalize_images().

Functions

decode_factor(matrix)

The largest reduction in 1, 2, 4, 8 that still leaves the warp at or below full resolution.

decoded_to_source(shape, height, width)

Map from a possibly reduced decode's pixel coordinates to the recorded image's.

Classes

Calibration(ego_to_camera, intrinsics, ...)

One camera's rig-static calibration.

CameraLoader(rig, images[, missing_camera])

Loads Cameras for a rig at one network input size.

Cameras(images, intrinsics, extrinsics, ...)

A rig's images for one frame, with the matrices that go with them.

class py123d_detection.torch.data.cameras.Calibration(ego_to_camera, intrinsics, height, width)[source]

Bases: object

One camera’s rig-static calibration.

ego_to_camera: ndarray

(4, 4) float32.

intrinsics: ndarray

(3, 3) float64, for the full-resolution image.

height: int
width: int
class py123d_detection.torch.data.cameras.Cameras(images, intrinsics, extrinsics, valid, source_sizes, size)[source]

Bases: object

A rig’s images for one frame, with the matrices that go with them.

images: ndarray

(N, 3, H_pad, W_pad) uint8, zero outside the image and for a missing camera.

intrinsics: ndarray

(N, 4, 4) float32, including everything done to the image. Identity where missing.

extrinsics: ndarray

(N, 4, 4) float32, ego to camera. Identity where missing.

valid: ndarray

(N,) bool, False where a camera had no image this frame.

source_sizes: List[Tuple[int, int, int]]

(height, width, 3) of each image as recorded.

size: Tuple[int, int]

(height, width) of every image before padding.

class py123d_detection.torch.data.cameras.CameraLoader(rig, images, missing_camera='skip')[source]

Bases: object

Loads Cameras for a rig at one network input size.

Parameters:

missing_camera (str) – "skip" rejects a frame with a camera missing, "zero" keeps it with that camera blank and marked invalid.

load(scene, iteration, draw)[source]

The rig’s cameras at one iteration, or None if the frame cannot be used.

Return type:

Optional[Cameras]

calibration(scene)[source]

Calibration of each rig camera the log has, read once per log from its metadata.

Return type:

Dict[str, Calibration]

py123d_detection.torch.data.cameras.decode_factor(matrix)[source]

The largest reduction in 1, 2, 4, 8 that still leaves the warp at or below full resolution.

A reduction is only taken where the result would still be at least as fine as the network input along both axes, so nothing the network could have seen is lost.

Return type:

int

py123d_detection.torch.data.cameras.decoded_to_source(shape, height, width)[source]

Map from a possibly reduced decode’s pixel coordinates to the recorded image’s.

A factor-f reduction averages f source pixels into one, so decoded pixel j sits at f * j + (f - 1) / 2 in the recorded image. The identity when nothing was reduced.

Return type:

ndarray