![]() |
VOOZH | about |
In this article, we are going to see how to draw bounding boxes on an image in PyTorch.
The draw_bounding_boxes function helps us to draw bounding boxes on an image. With tensor we provide shapes in [C, H, W], where C represents the number of channels and H, W represents the height and width respectively, this function returns an Image Tensor with bounding boxes. The bounding box should contain four points in format as (xmin, ymin, xmax, ymax), the top-left point=(xmin, ymin), and bottom-right point = (xmax, ymax).
Syntax - torch.utils.draw_bounding_boxes(image, box)
Parameter:
- image: Tensor of shape (C x H x W)
- box: Bounding boxes size in (xmin, ymin, xmax, ymax).
Return: Image Tensor of dtype uint8 with bounding boxes plotted.
The below image is used for demonstration:
The following example is to know how to change and fill colors in bounding boxes.
Output:
The following example is to understand how to draw multiple bounding boxes on an image.