courtvision.geometry
camera_space_to_world_space(camera_point, translation_vector, rotation_vector)
Transform a point from camera space to world space.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
camera_point |
np.array
|
3D point in camera space with shape (3,) |
required |
translation_vector |
np.array
|
Translation vector of the camera with shape (3,) |
required |
rotation_vector |
np.array
|
Rotation vector of the camera with shape (3,) |
required |
Raises:
Type | Description |
---|---|
ValueError
|
If the camera point is not a 3D point with shape (3,) |
Returns:
Type | Description |
---|---|
np.array
|
np.array: 3D point in world space with shape (3,) |
Source code in courtvision/geometry.py
1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 |
|
compute_ray_intersecting_plane(point_a_on_ray, point_b_on_ray, plane_normal=np.array([[0, 0, 1]]), plane_point=np.array([0, 0, 0]))
Given two points on a ray, compute the point of intersection with a plane. The plane is defined as a normal vector and a point on the plane.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
point_a_on_ray |
np.array
|
3D point on the ray with shape (3, 1) |
required |
point_b_on_ray |
np.array
|
3D point on the ray with shape (3, 1) |
required |
plane_normal |
np.array
|
Unit vector pointing out the plane. Defaults to np.array([[0, 0, 1]]). Shape (1, 3) |
np.array([[0, 0, 1]])
|
plane_point |
np.array
|
Point on the plane. Defaults to np.array([0, 0, 0]). Shape (3,) |
np.array([0, 0, 0])
|
Returns:
Type | Description |
---|---|
np.array: Returns the 3D point of intersection with shape (3,) |
Source code in courtvision/geometry.py
1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 |
|
convert_corners_to_coords(corners)
Convert corners_world_xx_n
to a numpy array of shape (12,)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
corners |
dict
|
|
required |
Returns:
Type | Description |
---|---|
np.ndarray
|
np.ndarray: numpy array of shape (12,) |
Source code in courtvision/geometry.py
425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 |
|
convert_corners_to_vec(corners)
Convert corners_world_xx_n
to a dict of vectors
Parameters:
Name | Type | Description | Default |
---|---|---|---|
corners |
dict
|
|
required |
Returns:
Name | Type | Description |
---|---|---|
dict |
dict
|
dict with keys x, y, z and numpy array of each |
Source code in courtvision/geometry.py
409 410 411 412 413 414 415 416 417 418 419 420 421 422 |
|
convert_obj_points_to_planar(object_points)
Converts object points to planar points by finding the common axis and permuting the points so that the common axis is the last axis. Assumes that the object points are planar.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
object_points |
np.array
|
description |
required |
Raises:
Type | Description |
---|---|
ValueError
|
When points are not planar |
Returns:
Type | Description |
---|---|
np.array
|
np.array: description |
Source code in courtvision/geometry.py
1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 |
|
denormalize_as_named_points(normalised_named_points, image_width, image_height)
Transforms a dict of normalized points 0 to 1
to image points using the
supplied image dimension.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
normalised_named_points |
dict[str, Point2D]
|
Dict of points normalised from |
required |
image_width |
int
|
Image width to expand to. |
required |
image_height |
int
|
Image height to expand to. |
required |
Returns:
Type | Description |
---|---|
dict[str, Point2D]
|
dict[str, Point2D]: Retruns a dict of similar struture but with image points. |
Source code in courtvision/geometry.py
1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 |
|
find_optimal_calibration_and_pose(valid_clip_ids, calibration_correspondences, pose_correspondences, image_width, image_height, all_image_points, all_world_points)
Givern a set of calibration and pose correspondences, find the optimal calibration and pose.
This is done by building up combinations of these sets and evaluating the reprojection error.
The reprojection error is the mean of the euclidean distance between the reprojected points and the actual points.
The evvaluation is on all all_image_points
and all_world_points
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
valid_clip_ids |
set[str]
|
description |
required |
calibration_correspondences |
list[tuple[np.array, np.array]]
|
description |
required |
pose_correspondences |
list[tuple[np.array, np.array]]
|
description |
required |
image_width |
int
|
Image width |
required |
image_height |
int
|
Image height |
required |
all_image_points |
np.array
|
3D points that we want to reproject. |
required |
all_world_points |
np.array
|
2D points that are where we expect the 3D points to be reprojected to. |
required |
Raises:
Type | Description |
---|---|
RuntimeError
|
description |
Returns:
Name | Type | Description |
---|---|---|
CameraInfo |
CameraInfo
|
description |
Source code in courtvision/geometry.py
1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 |
|
get_planar_point_correspondences(world_points, image_points, available_labels=None, minimal_set_count=4)
Given a set of named points in the world and image, return a list of point correspondences
where all points are coplanar.
If a specified set available_labels
is given, only return point correspondences where all
points are in that set.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
world_points |
dict[str, tuple[float, float]]
|
Dict of named points in the world coordinate frame. |
required |
image_points |
dict[str, tuple[float, float]]
|
Dict of named points in the image coordinate frame. |
required |
available_labels |
Optional[set[str]]
|
Set of labels to use if None all labels are used. Defaults to None. |
None
|
minimal_set_count |
int
|
Sets of corresponding points . Defaults to 4. |
4
|
Returns:
Type | Description |
---|---|
list[tuple[np.ndarray, np.ndarray]]
|
list[tuple[np.ndarray, np.ndarray]]: Returns a list of point correspondences where all points are coplanar. |
list[tuple[np.ndarray, np.ndarray]]
|
list[tuple[Nx3, Nx2]] |
Source code in courtvision/geometry.py
663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 |
|
project_points_to_base_plane(points, H)
Given homogeneous points or 2D points and a homography, project the points to the base plane
Parameters:
Name | Type | Description | Default |
---|---|---|---|
points |
torch.tensor
|
Homogeneous points or 2D points |
required |
H |
torch.tensor
|
Homography 3x3 matrix |
required |
Raises:
Type | Description |
---|---|
ValueError
|
If |
Returns:
Type | Description |
---|---|
torch.tensor
|
torch.tensor: Projected points in either homogeneous or 2D corrdinates. Same as |
Source code in courtvision/geometry.py
386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 |
|
solve_for_camera_matrix(world_points, image_points, image_size, repo_erro_threshold=0.1)
From a set of world points and image points, solve for the camera matrix and distortion coefficients. Note: All world points must have the same z value. i.e lie on the same plane.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
world_points |
torch.Tensor
|
Tensor of world points. |
required |
image_points |
torch.Tensor
|
Tensor of image points. |
required |
image_size |
tuple[int, int]
|
Image dimensions as (Width, Height). |
required |
repo_error |
float
|
Reprojection error measured in pixels. Defaults to 1e-1. |
required |
Returns (Tuple[torch.Tensor, torch.Tensor, float]): camera_matrix (3x3), dist_coeffs (1x5), repo_erro
Source code in courtvision/geometry.py
844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 |
|