Package 'ovml.common'

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

Help Index


The IOU of two bounding boxes

Description

The IOU of two bounding boxes

Usage

bbox_iou(box1, box2)

Arguments

box1

numeric: 4-element box vector

box2

matrix: nx4 matrix of boxes

Value

A vector of length n with the intersection over union (IOU) value for each box pair


Check file SHA1 hash against expected

Description

Check file SHA1 hash against expected

Usage

check_sha1(filename, expected = NULL)

Arguments

filename

string: file to check

expected

string: expected SHA1 hash

Value

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

Description

Path to the cache directory used for model weight files and other data

Usage

ovml_cache_dir()

Value

The path as a string


Class labels

Description

Class labels

Usage

ovml_class_labels(dataset = "coco")

Arguments

dataset

string: which dataset? One of

  • "coco" (used with a variety of models)

  • "mvb" (used with e.g. the yolov4-mvb model)

Value

A character vector of class labels


Conditional download utility

Description

If the file already exists in the ovml_cache_dir(), it won't be downloaded.

Usage

ovml_download_if(url, dest, expected_sha1 = NULL)

Arguments

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

Value

The path to the file in the ovml_cache_dir()


Example images

Description

Example images

Usage

ovml_example_image(choices = 1)

Arguments

choices

integer: which image files to return?

  • 1 - an image from a match between GKS Katowice and MKS Bedzin during the 2018/19 Polish Plus Liga

  • 2 - the standard YOLO dog image

Value

Path to the image files


Preview plot of detections over image using base graphics

Description

Preview plot of detections over image using base graphics

Usage

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"
)

Arguments

img

string or image: filename of jpg image, or image as read by [jpeg::readJPEG()]

detections

data.frame: as returned by e.g. ovml::ovml_yolo_detect()

line_args

list: parameters passed to lines (for ovml_plot()) or [ggplot2::geom_rect()] (for ovml_ggplot())

label_args

list: parameters passed to text

label_geom

string: for ovml_ggplot(), the geom function to use for labels. Either "text" (use [ggplot2::geom_text()]) or "label" ([ggplot2::geom_label()])

Examples

## 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)

ovml.common

Description

Support functions for other openvolley machine learning packages in volleyball analytics.


Process raw detections from pose detection network

Description

Process raw detections from pose detection network

Usage

process_pose_dets(
  pose,
  original_w,
  original_h,
  input_image_size,
  as = "segments",
  letterboxing = FALSE
)

Arguments

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

Value

A data.frame


Rescale boxes

Description

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.

Usage

rescale_boxes(
  bboxes,
  original_w,
  original_h,
  input_image_size,
  letterboxing = TRUE
)

Arguments

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?

Value

Rescaled boxes


Internal utilities

Description

Internal utilities

Usage

str_trim(x)

is_num_scalar(x)

x %eq% y

make_divisible(x, divisor)

image_wh(im)

image_resz(im, sz, preserve_aspect = TRUE)

Arguments

x, y, divisor, im, sz, preserve_aspect

: generic input parms


Convert xywh format to bounding box format

Description

Convert xywh format to bounding box format

Usage

xywh2box(prediction)

Arguments

prediction

matrix: n x m x q matrix of predictions, where the first 4 columns in q are x y w h

Value

A matrix of the same size, with coordinates changed to xmin, ymin, xmax, ymax