Learn R Programming

torchvision (version 0.7.0)

draw_bounding_boxes: Draws bounding boxes on image.

Description

Draws bounding boxes on top of one image tensor

Usage

draw_bounding_boxes(x, ...)

# S3 method for default draw_bounding_boxes(x, ...)

# S3 method for torch_tensor draw_bounding_boxes( x, boxes, labels = NULL, colors = NULL, fill = FALSE, width = 1, font = c("serif", "plain"), font_size = 10, ... )

# S3 method for image_with_bounding_box draw_bounding_boxes(x, ...)

Value

torch_tensor of size (C, H, W) of dtype uint8: Image Tensor with bounding boxes plotted.

Arguments

x

Tensor of shape (C x H x W) and dtype uint8 or dtype float. In case of dtype float, values are assumed to be in range \([0, 1]\). C value for channel can only be 1 (grayscale) or 3 (RGB).

...

Additional arguments passed to methods.

boxes

Tensor of size (N, 4) containing N bounding boxes in c(\(x_{min}\), \(y_{min}\), \(x_{max}\), \(y_{max}\)). format. Note that the boxes coordinates are absolute with respect to the image. In other words: \(0 \leq x_{min} < x_{max} < W \) and \(0 \leq y_{min} < y_{max} < W \).

labels

character vector containing the labels of bounding boxes.

colors

character vector containing the colors of the boxes or single color for all boxes. The color can be represented as strings e.g. "red" or "#FF00FF". By default, viridis colors are generated for boxes.

fill

If TRUE fills the bounding box with specified color.

width

Width of text shift to the bounding box.

font

NULL for the current font family, or a character vector of length 2 for Hershey vector fonts.

font_size

The requested font size in points.

See Also

Other image display: draw_keypoints(), draw_segmentation_masks(), tensor_image_browse(), tensor_image_display(), vision_make_grid()

Examples

Run this code
if (torch::torch_is_installed()) {
if (FALSE) {
image_tensor <- torch::torch_randint(170, 250, size = c(3, 360, 360))$to(torch::torch_uint8())
x <- torch::torch_randint(low = 1, high = 160, size = c(12,1))
y <- torch::torch_randint(low = 1, high = 260, size = c(12,1))
boxes <- torch::torch_cat(c(x, y, x + 20, y +  10), dim = 2)
bboxed <- draw_bounding_boxes(image_tensor, boxes, colors = "black", fill = TRUE)
tensor_image_browse(bboxed)
}
}

Run the code above in your browser using DataLab