py123d_detection.torch.visualize.cameras

Boxes drawn onto the camera images they were predicted from.

A bird’s-eye view tells you where the model put a box; this tells you what it was looking at when it did. Between them they separate the two failure modes that look identical in a metric: the object was invisible, or the object was visible and the model missed it.

Projection is py123d_detection.torch.models.bevformer.utils.project_3d_to_cameras(), the same function the BEVFormer encoder uses to decide which cameras see a BEV cell, rather than a second implementation of the same arithmetic. It also returns the validity mask, which is what lets an edge leaving the frame be dropped instead of drawn to a clamped corner.

Module Attributes

TRUTH_COLOUR

BGR, since cv2 draws in BGR.

THICKNESS

Stroke width in pixels.

Functions

draw_boxes(image, boxes, imu2img[, colour, ...])

Draw each box's twelve edges onto a copy of image.

project_corners(corners_3d, imu2img, image_size)

(N, 8, 3) corners to (N, 8, 2) pixels, with a (N, 8) validity mask.

render_camera(image, imu2img, predictions[, ...])

One camera image with ground truth under the predictions.

save_cameras(path, images[, columns])

Write a tiled rig view to a file.

shade(colour, score)

A prediction's colour: grey at score 0, the full colour at 1.

tile(images[, columns])

Lay a rig's cameras out in a grid, so one picture covers the whole frame.

py123d_detection.torch.visualize.cameras.TRUTH_COLOUR = (0, 140, 255)

BGR, since cv2 draws in BGR. The same two colours the bird’s-eye view uses, so the two panels of a frame read as one picture: ground truth orange, predictions blue shaded by confidence.

py123d_detection.torch.visualize.cameras.THICKNESS = 3

Stroke width in pixels. Predictions get the full width and ground truth half of it, which keeps them apart where a 3D box drawn on a 2D image cannot use fill.

py123d_detection.torch.visualize.cameras.shade(colour, score)[source]

A prediction’s colour: grey at score 0, the full colour at 1.

Return type:

Tuple[int, int, int]

py123d_detection.torch.visualize.cameras.project_corners(corners_3d, imu2img, image_size)[source]

(N, 8, 3) corners to (N, 8, 2) pixels, with a (N, 8) validity mask.

Parameters:
  • imu2img (ndarray) – (4, 4) projection for one camera, as the dataset supplies it.

  • image_size (Tuple[int, int]) – (height, width) of the image being drawn on.

Return type:

Tuple[ndarray, ndarray]

py123d_detection.torch.visualize.cameras.draw_boxes(image, boxes, imu2img, colour=PREDICTION_COLOUR, thickness=THICKNESS, scores=None)[source]

Draw each box’s twelve edges onto a copy of image.

An edge is drawn only where both of its corners project in front of the camera and inside the frame. A box partly out of view therefore appears partly drawn, which is honest: joining it to a clamped corner would invent a shape the model never predicted.

Return type:

ndarray

py123d_detection.torch.visualize.cameras.render_camera(image, imu2img, predictions, ground_truth=None, scores=None, score_threshold=SCORE_THRESHOLD, thickness=THICKNESS)[source]

One camera image with ground truth under the predictions.

Ground truth goes down first, in orange and at half the stroke width; predictions go on top in blue, shaded towards grey by their score. Boxes are in the frame imu2img projects from, which for this dataset is the ego frame.

Return type:

ndarray

py123d_detection.torch.visualize.cameras.tile(images, columns=3)[source]

Lay a rig’s cameras out in a grid, so one picture covers the whole frame.

Cameras of a rig need not share a resolution, and Argoverse 2’s do not, so each row is padded to its widest member rather than assuming they match.

Return type:

ndarray

py123d_detection.torch.visualize.cameras.save_cameras(path, images, columns=3)[source]

Write a tiled rig view to a file.

Return type:

None