Title: | Support Utilities for Volleyball Machine Learning |
---|---|
Description: | Support functions for other openvolley machine learning packages in volleyball analytics. |
Authors: | Ben Raymond [aut, cre], Adrien Ickowicz [aut], openvolley.org [org] |
Maintainer: | Ben Raymond <[email protected]> |
License: | MIT + file LICENSE |
Version: | 0.0.5 |
Built: | 2024-10-14 02:45:55 UTC |
Source: | https://github.com/openvolley/ovml.common |
The IOU of two bounding boxes
bbox_iou(box1, box2)
bbox_iou(box1, box2)
box1 |
numeric: 4-element box vector |
box2 |
matrix: nx4 matrix of boxes |
A vector of length n with the intersection over union (IOU) value for each box pair
Check file SHA1 hash against expected
check_sha1(filename, expected = NULL)
check_sha1(filename, expected = NULL)
filename |
string: file to check |
expected |
string: expected SHA1 hash |
TRUE
if the SHA1 hash matches the expected value, or if no expected value was provided.
Path to the cache directory used for model weight files and other data
ovml_cache_dir()
ovml_cache_dir()
The path as a string
Class labels
ovml_class_labels(dataset = "coco")
ovml_class_labels(dataset = "coco")
dataset |
string: which dataset? One of
|
A character vector of class labels
If the file already exists in the ovml_cache_dir()
, it won't be downloaded.
ovml_download_if(url, dest, expected_sha1 = NULL)
ovml_download_if(url, dest, expected_sha1 = NULL)
url |
string: URL of file to download |
dest |
string: local basename of file, if missing will be taken from the URL |
expected_sha1 |
string: the expected SHA1 hash of the file |
The path to the file in the ovml_cache_dir()
Example images
ovml_example_image(choices = 1)
ovml_example_image(choices = 1)
choices |
integer: which image files to return?
|
Path to the image files
Preview plot of detections over image using base graphics
ovml_plot( img, detections, line_args = list(col = "blue", lwd = 1), label_args = list(col = "white", cex = 0.75) ) ovml_ggplot( img, detections, line_args = list(col = "blue", size = 0.75, fill = NA), label_args = list(col = "white", size = 2.5, fill = "blue"), label_geom = "label" )
ovml_plot( img, detections, line_args = list(col = "blue", lwd = 1), label_args = list(col = "white", cex = 0.75) ) ovml_ggplot( img, detections, line_args = list(col = "blue", size = 0.75, fill = NA), label_args = list(col = "white", size = 2.5, fill = "blue"), label_geom = "label" )
img |
string or image: filename of jpg image, or image as read by [ |
detections |
data.frame: as returned by e.g. |
line_args |
list: parameters passed to lines (for |
label_args |
list: parameters passed to text |
label_geom |
string: for |
## Not run: ## define some demo data dets <- data.frame(class = rep("person", 3), score = rep(0.99, 3), xmin = c(829, 611, 736), xmax = c(960, 733, 836), ymin = c(88, 258, 213), ymax = c(278, 444, 385), stringsAsFactors = FALSE) img <- ovml_example_image(1) ovml_plot(img, dets, line_args = list(col = "red", lwd = 2)) ovml_ggplot(img, dets) + ggplot2::theme_void() ## End(Not run)
## Not run: ## define some demo data dets <- data.frame(class = rep("person", 3), score = rep(0.99, 3), xmin = c(829, 611, 736), xmax = c(960, 733, 836), ymin = c(88, 258, 213), ymax = c(278, 444, 385), stringsAsFactors = FALSE) img <- ovml_example_image(1) ovml_plot(img, dets, line_args = list(col = "red", lwd = 2)) ovml_ggplot(img, dets) + ggplot2::theme_void() ## End(Not run)
Support functions for other openvolley machine learning packages in volleyball analytics.
Process raw detections from pose detection network
process_pose_dets( pose, original_w, original_h, input_image_size, as = "segments", letterboxing = FALSE )
process_pose_dets( pose, original_w, original_h, input_image_size, as = "segments", letterboxing = FALSE )
pose |
matrix: pose detection network output |
original_w |
integer: input image width |
original_h |
integer: input image height |
input_image_size |
integer: network image size |
as |
string: return results as "segments" or "keypoints" |
letterboxing |
logical: TRUE if the input images were letterboxed to retain their original aspect ratio |
A data.frame
Detection boxes are generally on a scaled image, with size according to the network configuration. This function takes boxes on those images and rescales back to the original image dimensions, optionally accounting for letterboxing.
rescale_boxes( bboxes, original_w, original_h, input_image_size, letterboxing = TRUE )
rescale_boxes( bboxes, original_w, original_h, input_image_size, letterboxing = TRUE )
bboxes |
numeric: boxes |
original_w |
numeric: original image width in pixels |
original_h |
numeric: original image height in pixels |
input_image_size |
numeric: the network image size in pixels |
letterboxing |
logical: were the input images letterboxed? |
Rescaled boxes
Internal utilities
str_trim(x) is_num_scalar(x) x %eq% y make_divisible(x, divisor) image_wh(im) image_resz(im, sz, preserve_aspect = TRUE)
str_trim(x) is_num_scalar(x) x %eq% y make_divisible(x, divisor) image_wh(im) image_resz(im, sz, preserve_aspect = TRUE)
x , y , divisor , im , sz , preserve_aspect
|
: generic input parms |
Convert xywh format to bounding box format
xywh2box(prediction)
xywh2box(prediction)
prediction |
matrix: n x m x q matrix of predictions, where the first 4 columns in q are x y w h |
A matrix of the same size, with coordinates changed to xmin, ymin, xmax, ymax