R/target-transforms-detection.R
target_transform_rotate.RdConverts 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)An object_detection_target, as returned by the .getitem()
method of an object detection dataset, or a bare list containing
at least:
boxes — tensor of shape (N, 4) with bounding boxes in xyxy format
image_height (optional) — original image height, used for
clamping boxes to remain within image bounds
image_width (optional) — original image width, used for
clamping boxes to remain within image bounds
Other fields (labels, etc.) are preserved unchanged
(numeric): Rotation angle in degrees (counter-clockwise).
Default is 0.
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()
if (FALSE) { # \dontrun{
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))
} # }