Geometry
Module including geometric routines.
This module contains the following functions:
essential_from_features(src_image_file, tgt_image_file, K)
- Computes the essential matrix between two images using image features.fundamental_from_KP(K, P_src, P_tgt)
- Computes the fundamental matrix between two images using camera parameters.fundamental_from_features(src_image_file, tgt_image_file)
- Computes the fundamental matrix between two images using image features.geometric_consistency_mask(src_depth, src_cam, tgt_depth, tgt_cam, pixel_th)
- Computes the geometric consistency mask between a source and target depth map.homography(src_image_file, tgt_image_file)
- Computes a homography transformation between two images using image features.match_features(src_image, tgt_image, max_features)
- Computer matching ORB features between a pair of images.point_cloud_from_depth(depth, cam, color)
- Creates a point cloud from a single depth map.points_from_depth(depth, cam)
- Creates a point array from a single depth map.project_depth_map(depth, cam, mask)
- Projects a depth map into a list of 3D points.project_renderer(renderer, K, P, width, height)
- Projects the scene in an Open3D Offscreen Renderer to the 2D image plane.render_custom_values(points, values, image_shape, cam)
- Renders a point cloud into a 2D camera plane using custom values for each pixel.render_point_cloud(cloud, cam, width, height)
- Renders a point cloud into a 2D image plane.reproject(src_depth, src_cam, tgt_depth, tgt_cam)
- Computes the re-projection depth values and pixel indices between two depth maps.visibility_mask(src_depth, src_cam, depth_files, cam_files, src_ind=-1, pixel_th=0.1)
- Computes a visibility mask between a provided source depth map and list of target depth maps.
compute_plane_coords(K, P, depth_hypos, H, W)
Batched PyTorch version
Source code in cvt/geometry.py
291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 |
|
essential_from_features(src_image_file, tgt_image_file, K)
Computes the essential matrix between two images using image features.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
src_image_file |
str
|
Input file for the source image. |
required |
tgt_image_file |
str
|
Input file for the target image. |
required |
K |
np.ndarray
|
Intrinsics matrix of the two cameras (assumed to be constant between views). |
required |
Returns:
Type | Description |
---|---|
np.ndarray
|
The essential matrix betweent the two image views. |
Source code in cvt/geometry.py
337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 |
|
fundamental_from_KP(K, P_src, P_tgt)
Computes the fundamental matrix between two images using camera parameters.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
K |
np.ndarray
|
Intrinsics matrix of the two cameras (assumed to be constant between views). |
required |
P_src |
np.ndarray
|
Extrinsics matrix for the source view. |
required |
P_tgt |
np.ndarray
|
Extrinsics matrix for the target view. |
required |
Returns:
Type | Description |
---|---|
np.ndarray
|
The fundamental matrix betweent the two cameras. |
Source code in cvt/geometry.py
359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 |
|
fundamental_from_features(src_image_file, tgt_image_file)
Computes the fundamental matrix between two images using image features.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
src_image_file |
str
|
Input file for the source image. |
required |
tgt_image_file |
str
|
Input file for the target image. |
required |
Returns:
Type | Description |
---|---|
np.ndarray
|
The fundamental matrix betweent the two image views. |
Source code in cvt/geometry.py
389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 |
|
geometric_consistency_error(src_depth, src_cam, tgt_depth, tgt_cam)
Computes the geometric consistency error between a source and target depth map.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
src_depth |
np.ndarray
|
Depth map for the source view. |
required |
src_cam |
np.ndarray
|
Camera parameters for the source depth map viewpoint. |
required |
tgt_depth |
np.ndarray
|
Depth map for the target view. |
required |
tgt_cam |
np.ndarray
|
Camera parameters for the target depth map viewpoint. |
required |
Returns:
Type | Description |
---|---|
np.ndarray
|
The binary consistency mask encoding depth consensus between source and target depth maps. |
Source code in cvt/geometry.py
436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 |
|
geometric_consistency_mask(src_depth, src_K, src_P, tgt_depth, tgt_K, tgt_P, pixel_th)
Computes the geometric consistency mask between a source and target depth map.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
src_depth |
Depth map for the source view. |
required | |
src_K |
Intrinsic camera parameters for the source depth map viewpoint. |
required | |
src_P |
Extrinsic camera parameters for the source depth map viewpoint. |
required | |
tgt_depth |
Target depth map used for re-projection. |
required | |
tgt_K |
Intrinsic camera parameters for the target depth map viewpoint. |
required | |
tgt_P |
Extrinsic camera parameters for the target depth map viewpoint. |
required | |
pixel_th |
Pixel re-projection threshold to determine matching depth estimates. |
required |
Returns:
Type | Description |
---|---|
The binary consistency mask encoding depth consensus between source and target depth maps. |
Source code in cvt/geometry.py
410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 |
|
homography(src_image_file, tgt_image_file)
Computes a homography transformation between two images using image features.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
src_image_file |
str
|
Input file for the source image. |
required |
tgt_image_file |
str
|
Input file for the target image. |
required |
Returns:
Type | Description |
---|---|
np.ndarray
|
The homography matrix to warp the target image to the source image. |
Source code in cvt/geometry.py
457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 |
|
match_features(src_image, tgt_image, max_features=500)
Computer matching ORB features between a pair of images.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
src_image |
np.ndarray
|
The source image to compute and match features. |
required |
tgt_image |
np.ndarray
|
The target image to compute and match features. |
required |
max_features |
int
|
The maximum number of features to retain. |
500
|
Returns:
Name | Type | Description |
---|---|---|
src_points |
np.ndarray
|
The set of matched point coordinates for the source image. |
tgt_points |
np.ndarray
|
The set of matched point coordinates for the target image. |
Source code in cvt/geometry.py
479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 |
|
point_cloud_from_depth(depth, cam, color)
Creates a point cloud from a single depth map.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
depth |
np.ndarray
|
Depth map to project to 3D. |
required |
cam |
np.ndarray
|
Camera parameters for the given depth map viewpoint. |
required |
color |
np.ndarray
|
Color [R,G,B] used for all points in the generated point cloud. |
required |
Source code in cvt/geometry.py
515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 |
|
points_from_depth(depth, cam)
Creates a point array from a single depth map.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
depth |
np.ndarray
|
Depth map to project to 3D. |
required |
cam |
np.ndarray
|
Camera parameters for the given depth map viewpoint. |
required |
Returns:
Type | Description |
---|---|
np.ndarray
|
An array of 3D points corresponding to the input depth map. |
Source code in cvt/geometry.py
763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 |
|
project_depth_map(depth, cam, mask=None)
Projects a depth map into a list of 3D points
Parameters:
Name | Type | Description | Default |
---|---|---|---|
depth |
torch.Tensor
|
Input depth map to project. |
required |
cam |
torch.Tensor
|
Camera parameters for input depth map. |
required |
Returns:
Type | Description |
---|---|
torch.Tensor
|
A float Tensor of 3D points corresponding to the projected depth values. |
Source code in cvt/geometry.py
787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 |
|
project_renderer(renderer, K, P, width, height)
Projects the scene in an Open3D Offscreen Renderer to the 2D image plane.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
renderer |
o3d.visualization.rendering.OffscreenRenderer
|
Geometric scene to be projected. |
required |
K |
np.ndarray
|
Camera intrinsic parameters. |
required |
P |
np.ndarray
|
Camera extrinsic parameters. |
required |
width |
float
|
Desired image width. |
required |
height |
float
|
Desired image height. |
required |
Returns:
Type | Description |
---|---|
np.ndarray
|
The rendered image for the scene at the specified camera viewpoint. |
Source code in cvt/geometry.py
841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 |
|
render_custom_values(points, values, image_shape, cam)
Renders a point cloud into a 2D camera plane using custom values for each pixel.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
points |
np.ndarray
|
List of 3D points to be rendered. |
required |
values |
np.ndarray
|
List of values to be written in the rendered image. |
required |
image_shape |
Tuple[int, int]
|
Desired shape (height,width) of the rendered image. |
required |
cam |
np.ndarray
|
Camera parameters for the image viewpoint. |
required |
Returns:
Type | Description |
---|---|
np.ndarray
|
The rendered image for the list of points using the sepcified corresponding values. |
Source code in cvt/geometry.py
864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 |
|
render_point_cloud(cloud, cam, width, height)
Renders a point cloud into a 2D image plane.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
cloud |
o3d.geometry.PointCloud
|
Point cloud to be rendered. |
required |
cam |
np.ndarray
|
Camera parameters for the image plane. |
required |
width |
int
|
Desired width of the rendered image. |
required |
height |
int
|
Desired height of the rendered image. |
required |
Returns:
Type | Description |
---|---|
np.ndarray
|
The rendered image for the point cloud at the specified camera viewpoint. |
Source code in cvt/geometry.py
920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 |
|
reproject(src_depth, src_K, src_P, tgt_depth, tgt_K, tgt_P)
Computes the re-projection depth values and pixel indices between two depth maps.
This function takes as input two depth maps: 'src_depth' and 'tgt_depth'. The source depth map is first projected into the target camera plane using the source depth values and the camera parameters for both views. Using the projected pixel coordinates in the target view, the target depths are then re-projected back into the source camera plane (again with the camera parameters for both views). The information prouced from this process is often used to compute errors in re-projection between two depth maps, or similar operations.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
src_depth |
Source depth map to be projected. |
required | |
src_K |
Intrinsic camera parameters for the source depth map viewpoint. |
required | |
src_P |
Extrinsic camera parameters for the source depth map viewpoint. |
required | |
tgt_depth |
Target depth map used for re-projection. |
required | |
tgt_K |
Intrinsic camera parameters for the target depth map viewpoint. |
required | |
tgt_P |
Extrinsic camera parameters for the target depth map viewpoint. |
required |
Returns:
Name | Type | Description |
---|---|---|
depth_reprojected | The re-projected depth values for the source depth map. |
|
coords_reprojected | The re-projection coordinates for the source view. |
|
coords_tgt | The projected coordinates for the target view. |
Source code in cvt/geometry.py
951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 |
|
visibility_mask(src_depth, src_cam, depth_files, cam_files, src_ind=-1, pixel_th=0.1)
Computes a visibility mask between a provided source depth map and list of target depth maps.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
src_depth |
np.ndarray
|
Depth map for the source view. |
required |
src_cam |
np.ndarray
|
Camera parameters for the source depth map viewpoint. |
required |
depth_files |
List[str]
|
List of target depth maps. |
required |
cam_files |
List[str]
|
List of corresponding target camera parameters for each targte depth map viewpoint. |
required |
src_ind |
int
|
Index into 'depth_files' corresponding to the source depth map (if included in the list). |
-1
|
pixel_th |
float
|
Pixel re-projection threshold to determine matching depth estimates. |
0.1
|
Returns:
Type | Description |
---|---|
np.ndarray
|
The visibility mask for the source view. |
Source code in cvt/geometry.py
1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 |
|
warp_to_tgt(tgt_depth, tgt_conf, ref_cam, tgt_cam, depth_planes, depth_vol)
Performs a homography warping
Parameters:
Name | Type | Description | Default |
---|---|---|---|
tgt_depth |
torch.Tensor
|
required | |
tgt_conf |
torch.Tensor
|
required | |
ref_cam |
torch.Tensor
|
required | |
tgt_cam |
torch.Tensor
|
required | |
depth_planes |
torch.Tensor
|
required | |
depth_vol |
torch.Tensor
|
required |
Returns:
Name | Type | Description |
---|---|---|
depth_diff |
torch.Tensor
|
|
warped_conf |
torch.Tensor
|
Source code in cvt/geometry.py
1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 |
|