View source: R/transformation.R
ov_transform_points | R Documentation |
The court coordinate system is that used in datavolley::dv_court()
, datavolley::ggcourt()
, and related functions.
Try plot(c(0, 4), c(0, 7), type = "n", asp = 1); datavolley::dv_court()
or ggplot2::ggplot() + datavolley::ggcourt() + ggplot2::theme_bw()
for a visual depiction.
Image coordinates are returned as normalized coordinates in the range [0, 1]
. You may need to scale these by the width and height of the image, depending on how you are plotting things.
ov_transform_points(x, y, ref, direction = "to_court")
x |
numeric: input x points. |
y |
numeric: input y points |
ref |
data.frame: reference, as returned by |
direction |
string: either "to_court" (to transform image coordinates to court coordinates) or "to_image" (the reverse) |
A two-column data.frame with transformed values
https://en.wikipedia.org/wiki/Camera_matrix. For general background see e.g. Ballard DH, Brown CM (1982) Computer Vision. Prentice-Hall, New Jersey
ov_get_court_ref()
, datavolley::dv_court()
, datavolley::ggcourt()
## the ref data for the example image
crt <- data.frame(image_x = c(0.05397063, 0.95402573, 0.75039756, 0.28921230),
image_y = c(0.02129301, 0.02294600, 0.52049712, 0.51884413),
court_x = c(0.5, 3.5, 3.5, 0.5),
court_y = c(0.5, 0.5, 6.5, 6.5))
## show the image
img <- jpeg::readJPEG(system.file("extdata/2019_03_01-KATS-BEDS-court.jpg",
package = "ovideo"))
plot(c(0, 1), c(0, 1), type = "n", axes = FALSE, xlab = "", ylab = "",
asp = dim(img)[1]/dim(img)[2])
rasterImage(img, 0, 0, 1, 1)
## convert the ends of the 3m lines on court to image coordinates
check <- data.frame(x = c(0.5, 3.5, 0.5, 3.5),
y = c(2.5, 2.5, 4.5, 4.5))
ix <- ov_transform_points(check, ref = crt, direction = "to_image")
## and finally plot onto the image
points(ix$x, ix$y, pch = 21, bg = 4)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.