MCPcopy Create free account
hub / github.com/MotrixLab/AiOS / perspective_projection

Function perspective_projection

detrsmpl/utils/geometry.py:247–275  ·  view source on GitHub ↗

This function computes the perspective projection of a set of points. Input: points (bs, N, 3): 3D points rotation (bs, 3, 3): Camera rotation translation (bs, 3): Camera translation focal_length (bs,) or scalar: Focal length camera_center (bs, 2): Camera

(points, rotation, translation, focal_length,
                           camera_center)

Source from the content-addressed store, hash-verified

245
246
247def perspective_projection(points, rotation, translation, focal_length,
248 camera_center):
249 """This function computes the perspective projection of a set of points.
250
251 Input:
252 points (bs, N, 3): 3D points
253 rotation (bs, 3, 3): Camera rotation
254 translation (bs, 3): Camera translation
255 focal_length (bs,) or scalar: Focal length
256 camera_center (bs, 2): Camera center
257 """
258 batch_size = points.shape[0]
259 K = torch.zeros([batch_size, 3, 3], device=points.device)
260 K[:, 0, 0] = focal_length
261 K[:, 1, 1] = focal_length
262 K[:, 2, 2] = 1.
263 K[:, :-1, -1] = camera_center
264
265 # Transform points
266 points = torch.einsum('bij,bkj->bki', rotation, points)
267 points = points + translation.unsqueeze(1)
268
269 # Apply perspective distortion
270 projected_points = points / points[:, :, -1].unsqueeze(-1)
271
272 # Apply camera intrinsics
273 projected_points = torch.einsum('bij,bkj->bki', K, projected_points)
274
275 return projected_points[:, :, :-1]
276
277
278def estimate_translation_np(S,

Callers 2

project_pointsFunction · 0.70
project_points_newFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected