pipert.utils.visualizer.video_visualizer

Module Contents

Classes

ColorMode

Enum of different color modes to use for instance visualizations.

_DetectedInstance

Used to store data about detected objects in video frame,

VideoVisualizer

Functions

_create_text_labels(classes, scores, class_names, ids)

Args:

class pipert.utils.visualizer.video_visualizer.ColorMode[source]

Bases: enum.Enum

Enum of different color modes to use for instance visualizations.

Attributes:

IMAGE: Picks a random color for every instance and overlay segmentations with low opacity. SEGMENTATION: Let instances of the same category have similar colors, and overlay them with

high opacity. This provides more attention on the quality of segmentation.

IMAGE_BW: same as IMAGE, but convert all areas without masks to gray-scale.

Only available for drawing per-instance mask predictions.

IMAGE = 0[source]
SEGMENTATION = 1[source]
IMAGE_BW = 2[source]
class pipert.utils.visualizer.video_visualizer._DetectedInstance(label, bbox, mask_rle, color, ttl)[source]

Used to store data about detected objects in video frame, in order to transfer color to objects in the future frames.

Attributes:

label (int): bbox (tuple[float]): mask_rle (dict): color (tuple[float]): RGB colors in range (0, 1) ttl (int): time-to-live for the instance. For example, if ttl=2,

the instance color can be transferred to objects in the next two frames.

__slots__ = ['label', 'bbox', 'mask_rle', 'color', 'ttl'][source]
pipert.utils.visualizer.video_visualizer._create_text_labels(classes, scores, class_names, ids)[source]
Args:

classes (list[int] or None): scores (list[float] or None): class_names (list[str] or None): ids (list[int] or None):

Returns:

list[str] or None

class pipert.utils.visualizer.video_visualizer.VideoVisualizer(metadata, instance_mode=ColorMode.IMAGE)[source]
draw_instance_predictions(self, frame, predictions, names)[source]

Draw instance-level prediction results on an image.

Args:

frame (ndarray): an RGB image of shape (H, W, C), in the range [0, 255]. predictions (Instances): the output of an instance detection/segmentation

model. Following fields will be used to draw: “pred_boxes”, “pred_classes”, “scores”, “pred_masks” (or “pred_masks_rle”).

Returns:

output (VisImage): image object with visualizations.

draw_sem_seg(self, frame, sem_seg, area_threshold=None)[source]

Args: sem_seg (ndarray or Tensor): semantic segmentation of shape (H, W),

each value is the integer label.

area_threshold (Optional[int]): only draw segmentations larger than the threshold

_assign_colors(self, instances)[source]

Naive tracking heuristics to assign same color to the same instance, will update the internal state of tracked instances.

Returns:

list[tuple[float]]: list of colors.