@@ -129,6 +129,10 @@ def unproject_points(self):
129
129
coordinates using the camera extrinsics `R` and `T`.
130
130
`False` ignores `R` and `T` and unprojects to
131
131
the camera view coordinates.
132
+ from_ndc: If `False` (default), assumes xy part of input is in
133
+ NDC space if self.in_ndc(), otherwise in screen space. If
134
+ `True`, assumes xy is in NDC space even if the camera
135
+ is defined in screen space.
132
136
133
137
Returns
134
138
new_points: unprojected points with the same shape as `xy_depth`.
@@ -998,12 +1002,27 @@ def get_projection_transform(self, **kwargs) -> Transform3d:
998
1002
return transform
999
1003
1000
1004
def unproject_points (
1001
- self , xy_depth : torch .Tensor , world_coordinates : bool = True , ** kwargs
1005
+ self ,
1006
+ xy_depth : torch .Tensor ,
1007
+ world_coordinates : bool = True ,
1008
+ from_ndc : bool = False ,
1009
+ ** kwargs
1002
1010
) -> torch .Tensor :
1011
+ """
1012
+ Args:
1013
+ from_ndc: If `False` (default), assumes xy part of input is in
1014
+ NDC space if self.in_ndc(), otherwise in screen space. If
1015
+ `True`, assumes xy is in NDC space even if the camera
1016
+ is defined in screen space.
1017
+ """
1003
1018
if world_coordinates :
1004
1019
to_camera_transform = self .get_full_projection_transform (** kwargs )
1005
1020
else :
1006
1021
to_camera_transform = self .get_projection_transform (** kwargs )
1022
+ if from_ndc :
1023
+ to_camera_transform = to_camera_transform .compose (
1024
+ self .get_ndc_camera_transform ()
1025
+ )
1007
1026
1008
1027
unprojection_transform = to_camera_transform .inverse ()
1009
1028
xy_inv_depth = torch .cat (
@@ -1030,6 +1049,8 @@ def get_ndc_camera_transform(self, **kwargs) -> Transform3d:
1030
1049
For cameras defined in screen space, we adjust the principal point computation
1031
1050
which is defined in the image space (commonly) and scale the points to NDC space.
1032
1051
1052
+ This transform leaves the depth unchanged.
1053
+
1033
1054
Important: This transforms assumes PyTorch3D conventions for the input points,
1034
1055
i.e. +X left, +Y up.
1035
1056
"""
@@ -1199,12 +1220,27 @@ def get_projection_transform(self, **kwargs) -> Transform3d:
1199
1220
return transform
1200
1221
1201
1222
def unproject_points (
1202
- self , xy_depth : torch .Tensor , world_coordinates : bool = True , ** kwargs
1223
+ self ,
1224
+ xy_depth : torch .Tensor ,
1225
+ world_coordinates : bool = True ,
1226
+ from_ndc : bool = False ,
1227
+ ** kwargs
1203
1228
) -> torch .Tensor :
1229
+ """
1230
+ Args:
1231
+ from_ndc: If `False` (default), assumes xy part of input is in
1232
+ NDC space if self.in_ndc(), otherwise in screen space. If
1233
+ `True`, assumes xy is in NDC space even if the camera
1234
+ is defined in screen space.
1235
+ """
1204
1236
if world_coordinates :
1205
1237
to_camera_transform = self .get_full_projection_transform (** kwargs )
1206
1238
else :
1207
1239
to_camera_transform = self .get_projection_transform (** kwargs )
1240
+ if from_ndc :
1241
+ to_camera_transform = to_camera_transform .compose (
1242
+ self .get_ndc_camera_transform ()
1243
+ )
1208
1244
1209
1245
unprojection_transform = to_camera_transform .inverse ()
1210
1246
return unprojection_transform .transform_points (xy_depth )
0 commit comments