Table of Contents
Shortcuts

# draw_bounding_boxes

torchvision.utils.draw_bounding_boxes(image: Tensor, boxes: Tensor, labels: Optional[List[str]] = None, colors: Optional[Union[List[Union[str, Tuple[int, int, int]]], str, Tuple[int, int, int]]] = None, fill: Optional[bool] = False, width: int = 1, font: Optional[str] = None, font_size: Optional[int] = None) → Tensor

  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 (Tensor) – Tensor of shape (C x H x W) and dtype uint8.

    - boxes (Tensor) – Tensor of size (N, 4) containing bounding boxes in (xmin, ymin, xmax, ymax) format. Note that the boxes are absolute coordinates with respect to the image. In other words: 0 <= xmin < xmax < W and 0 <= ymin < ymax < H.

    - labels (List[str]) – List containing the labels of bounding boxes.

    - colors (color or list of colors, 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 (bool) – If True fills the bounding box with specified color.

    - width (int) – Width of bounding box.

    - font (str) – A filename containing a TrueType font. If the file is not found in this filename, the loader may also search in other directories, such as the fonts/ directory on Windows or /Library/Fonts/, /System/Library/Fonts/ and ~/Library/Fonts/ on macOS.

    - font_size (int) – The requested font size in points.

  Returns:

    Image Tensor of dtype uint8 with bounding boxes plotted.

  Return type:

    img (Tensor[C, H, W])

  Examples using `draw_bounding_boxes`:

  Visualization utilities

  Visualization utilities

## Docs

Access comprehensive developer documentation for PyTorch

View Docs

## Tutorials

Get in-depth tutorials for beginners and advanced developers

View Tutorials

## Resources

Find development resources and get your questions answered

View Resources

To analyze traffic and optimize your experience, we serve cookies on this site. By clicking or navigating, you agree to allow our usage of cookies. As the current maintainers of this site, Facebook’s Cookies Policy applies. Learn more, including about available controls: Cookies Policy.