@@ -91,6 +91,20 @@ def get_projection_matrix(self, width=None, height=None):
9191 """
9292 pass
9393
94+ @abc .abstractmethod
95+ def inverse_transform_depth_ndc (self , depth_ndc ):
96+ """
97+ Unproject the depth in Normalized Device Coordinates
98+ to metric values in eye (camera) reference frame.
99+ :param
100+ depth_ndc: np.array np.float32
101+ depth in [-1, 1] in normalized device coordinates
102+ :return:
103+ depth: np.array np.float32
104+ depth in metric units in eye (camera) reference frame.
105+ """
106+ pass
107+
94108
95109class PerspectiveCamera (Camera ):
96110
@@ -205,6 +219,19 @@ def get_projection_matrix(self, width=None, height=None):
205219
206220 return P
207221
222+ def inverse_transform_depth_ndc (self , depth_ndc ):
223+ inf_inds = (depth_ndc == 1 )
224+ noninf = np .logical_not (inf_inds )
225+ depth_img = depth_ndc
226+ if self .zfar is None :
227+ depth_img [noninf ] = 2 * self .znear / (1.0 - depth_img [noninf ])
228+ else :
229+ depth_img [noninf ] = ((2.0 * self .znear * self .zfar ) /
230+ (self .zfar + self .znear - depth_img [noninf ] *
231+ (self .zfar - self .znear )))
232+ depth_img [inf_inds ] = 0.0
233+ return depth_img
234+
208235
209236class OrthographicCamera (Camera ):
210237 """An orthographic camera for orthographic projection.
@@ -309,6 +336,17 @@ def get_projection_matrix(self, width=None, height=None):
309336 P [3 ][3 ] = 1.0
310337 return P
311338
339+ def inverse_transform_depth_ndc (self , depth_ndc ):
340+ inf_inds = (depth_ndc == 1 )
341+ noninf = np .logical_not (inf_inds )
342+ depth_img = depth_ndc
343+ if self .zfar is None :
344+ depth_img [noninf ] = 2 * self .znear / (1.0 - depth_img [noninf ])
345+ else :
346+ depth_img [noninf ] = (depth_img [noninf ] * (self .zfar - self .znear ) + self .zfar + self .znear ) / 2.0
347+ depth_img [inf_inds ] = 0.0
348+ return depth_img
349+
312350
313351class IntrinsicsCamera (Camera ):
314352 """A perspective camera with custom intrinsics.
@@ -432,6 +470,19 @@ def get_projection_matrix(self, width, height):
432470
433471 return P
434472
473+ def inverse_transform_depth_ndc (self , depth_ndc ):
474+ inf_inds = (depth_ndc == 1 )
475+ noninf = np .logical_not (inf_inds )
476+ depth_img = depth_ndc
477+ if self .zfar is None :
478+ depth_img [noninf ] = 2 * self .znear / (1.0 - depth_img [noninf ])
479+ else :
480+ depth_img [noninf ] = ((2.0 * self .znear * self .zfar ) /
481+ (self .zfar + self .znear - depth_img [noninf ] *
482+ (self .zfar - self .znear )))
483+ depth_img [inf_inds ] = 0.0
484+ return depth_img
485+
435486
436487__all__ = ['Camera' , 'PerspectiveCamera' , 'OrthographicCamera' ,
437488 'IntrinsicsCamera' ]
0 commit comments