draw_bounding_boxes | R Documentation |
Draws bounding boxes on top of one image tensor
draw_bounding_boxes(
image,
boxes,
labels = NULL,
colors = NULL,
fill = FALSE,
width = 1,
font = c("serif", "plain"),
font_size = 10
)
image |
: Tensor of shape (C x H x W) and dtype uint8. |
boxes |
: 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: |
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 |
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. |
torch_tensor of size (C, H, W) of dtype uint8: Image Tensor with bounding boxes plotted.
if (torch::torch_is_installed()) {
## Not run:
image <- 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, boxes, colors = "black", fill = TRUE)
tensor_image_browse(bboxed)
## End(Not run)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.