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 [source]¶
Draws bounding boxes on given RGB image. The image values should be uint8 in [0, 255] or float in [0, 1]. If fill is True, Resulting Tensor should be saved as PNG image.
- Parameters:
image (Tensor) – Tensor of shape (C, H, W) and dtype uint8 or float.
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
:Repurposing masks into bounding boxes
Repurposing masks into bounding boxesVisualization utilities