sportslabkit.utils.draw#

Overview#

Function#

draw_bounding_boxes(image, bboxes, labels, colors, fill, width, font, font_size)

Draws bounding boxes on given image.

draw_tracks(img, tracks, fill, width, font, font_size)

-

Functions#

sportslabkit.utils.draw.draw_bounding_boxes(image: numpy.ndarray, bboxes: numpy.ndarray, labels: list[str] | None = None, colors: list[str | tuple[int, int, int]] | str | tuple[int, int, int] | None = None, fill: bool | None = False, width: int = 1, font: str | None = None, font_size: int | None = None) numpy.ndarray[source]#

Draws bounding boxes on given image. The values of the input image should be uint8 between 0 and 255. If fill is True, Resulting Tensor should be saved as PNG image.

Parameters:
  • image (np.ndarray) – Image with shape (H x W x C) to draw bounding boxes on.

  • bboxes (np.ndarray) – Bounding boxes with in unnormalized xywh format with shape (N x 4) or with shape (N x 6) if confidence scores and class labels are provided. Note that the boxes are absolute coordinates with respect to the image. In other words: 0 <= x|w <= W and 0 <= y|h <= H.

  • labels (Optional[list[str]], optional) – Labels for bounding boxes. Defaults to None.

  • colors (Optional[Union[List[Union[str, Tuple[int, int, int]]], str, Tuple[int, int, int]]], optional) – List containing the colors of the boxes or single color for all boxes. The color can be represented as PIL strings e.g. “red” or “#FF00FF”, or as RGB tuples e.g. (240, 10, 157). By default, random colors are generated for boxes.

  • fill (Optional[bool], optional) – If true, fills bounding boxes with color. Defaults to False.

  • width (int, optional) – Width of bounding box lines. Defaults to 1.

  • font (Optional[str], optional) – Font to use for labels. Defaults to None.

  • font_size (Optional[int], optional) – Font size to use for labels. Defaults to None.

Returns:

Image ndarray of dtype uint8 with bounding boxes plotted.

Return type:

img (np.ndarray[H, W, C])

sportslabkit.utils.draw.draw_tracks(img, tracks, fill: bool | None = False, width: int = 1, font: str | None = None, font_size: int | None = None)[source]#