The camera matrix characterizes the mapping of a camera from 3D real-world coordinates to 2D coordinates in an image.
Arguments
- X
matrix or data.frame: Nx3 matrix of 3D real-world coordinates
- x
matrix or data.frame: Nx2 matrix of image coordinates
Value
A list with components coef
(fitted transformation coefficients) and rmse
(root mean squared error of the fitted transformation)
References
https://en.wikipedia.org/wiki/Camera_matrix. For general background see e.g. Ballard DH, Brown CM (1982) Computer Vision. Prentice-Hall, New Jersey
Examples
## define real-world and corresponding image coordinates
xX <- dplyr::tribble(~image_x, ~image_y, ~court_x, ~court_y, ~z,
0.054, 0.023, 0.5, 0.5, 0, ## near left baseline
0.951, 0.025, 3.5, 0.5, 0, ## near right baseline
0.752, 0.519, 3.5, 6.5, 0, ## far right baseline
0.288, 0.519, 0.5, 6.5, 0, ## far left baseline
0.199, 0.644, 0.5, 3.5, 2.43, ## left net top
0.208, 0.349, 0.5, 3.5, 0.00, ## left net floor
0.825, 0.644, 3.5, 3.5, 2.43, ## right net top
0.821, 0.349, 3.5, 3.5, 0.00) ## right net floor
C <- ov_cmat_estimate(X = xX[, 3:5], x = xX[, 1:2])
## fitted image coordinates using C
ov_cmat_apply(C, X = xX[, 3:5])
#> [,1] [,2]
#> [1,] 0.05437417 0.02263137
#> [2,] 0.95105054 0.02438193
#> [3,] 0.75249292 0.51875259
#> [4,] 0.28772625 0.51873571
#> [5,] 0.19900000 0.64414048
#> [6,] 0.20810535 0.34946240
#> [7,] 0.82500000 0.64385986
#> [8,] 0.82031638 0.34988510
## compare to actual image positions
xX[, 1:2]
#> # A tibble: 8 × 2
#> image_x image_y
#> <dbl> <dbl>
#> 1 0.054 0.023
#> 2 0.951 0.025
#> 3 0.752 0.519
#> 4 0.288 0.519
#> 5 0.199 0.644
#> 6 0.208 0.349
#> 7 0.825 0.644
#> 8 0.821 0.349