View source: R/target-transforms-detection.R
| target_transform_rotate | R Documentation |
Converts bounding boxes of a detection target from
(x_{min}, y_{min}, x_{max}, y_{max}) (xyxy) format to
(x_{min}, y_{min}, x_{max}, y_{max}, r) (xyxyr) format, where
r is the rotation angle in degrees (counter-clockwise).
For axis-aligned boxes, r = 0.
target_transform_rotate(target, angle = 0)
## S3 method for class 'object_detection_target'
target_transform_rotate(target, angle = 0)
## S3 method for class 'dataset'
target_transform_rotate(target, angle = 0)
target |
An
|
angle |
(numeric): Rotation angle in degrees (counter-clockwise).
Default is |
A list with the same structure as the input target, where
boxes is a tensor of shape (N, 5) in xyxyr format.
When applied to a dataset, returns the same dataset with its
.getitem method modified to return rotated-box targets.
Other target_transforms_detection:
prepare_sahi_split(),
target_transform_affine(),
target_transform_resize()
## Not run:
url <- "https://upload.wikimedia.org/wikipedia/commons/6/66/The_Leaning_Tower_of_Pisa_SB.jpeg"
img <- base_loader(url) |> transform_to_tensor()
boxes <- torch_tensor(matrix(c(720, 620, 1900, 3700), ncol = 4), dtype = torch_float32())
# Original boxes (blue, axis-aligned)
before_plot <- draw_bounding_boxes(img, boxes = boxes, colors = "blue", width = 10)
# Transform boxes to xyxyr with 4 degree rotation
target <- list(
boxes = boxes,
image_height = img$shape[2],
image_width = img$shape[3]
)
class(target) <- c("object_detection_target", "list")
rotated_target <- target_transform_rotate(target, angle = 4)
# Rotated boxes (red, drawn as polygons)
after_plot <- draw_bounding_boxes(img, boxes = rotated_target$boxes, colors = "red", width = 10)
tensor_image_browse(vision_make_grid(before_plot, after_plot, scale = TRUE))
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.