MCPcopy Create free account
hub / github.com/InternRobotics/EmbodiedScan / points_img2cam

Function points_img2cam

embodiedscan/structures/bbox_3d/utils.py:336–368  ·  view source on GitHub ↗

Project points in image coordinates to camera coordinates. Args: points (Tensor or np.ndarray): 2.5D points in 2D images with shape [N, 3], 3 corresponds with x, y in the image and depth. cam2img (Tensor or np.ndarray): Camera intrinsic matrix. The shape can

(
        points: Union[Tensor, np.ndarray],
        cam2img: Union[Tensor, np.ndarray])

Source from the content-addressed store, hash-verified

334
335@array_converter(apply_to=('points', 'cam2img'))
336def points_img2cam(
337 points: Union[Tensor, np.ndarray],
338 cam2img: Union[Tensor, np.ndarray]) -> Union[Tensor, np.ndarray]:
339 """Project points in image coordinates to camera coordinates.
340
341 Args:
342 points (Tensor or np.ndarray): 2.5D points in 2D images with shape
343 [N, 3], 3 corresponds with x, y in the image and depth.
344 cam2img (Tensor or np.ndarray): Camera intrinsic matrix. The shape can
345 be [3, 3], [3, 4] or [4, 4].
346
347 Returns:
348 Tensor or np.ndarray: Points in 3D space with shape [N, 3], 3
349 corresponds with x, y, z in 3D space.
350 """
351 assert cam2img.shape[0] <= 4
352 assert cam2img.shape[1] <= 4
353 assert points.shape[1] == 3
354
355 xys = points[:, :2]
356 depths = points[:, 2].view(-1, 1)
357 unnormed_xys = torch.cat([xys * depths, depths], dim=1)
358
359 pad_cam2img = torch.eye(4, dtype=xys.dtype, device=xys.device)
360 pad_cam2img[:cam2img.shape[0], :cam2img.shape[1]] = cam2img
361 inv_pad_cam2img = torch.inverse(pad_cam2img).transpose(0, 1)
362
363 # Do operation in homogeneous coordinates.
364 num_points = unnormed_xys.shape[0]
365 homo_xys = torch.cat([unnormed_xys, xys.new_ones((num_points, 1))], dim=1)
366 points3D = torch.mm(homo_xys, inv_pad_cam2img)[:, :3]
367
368 return points3D
369
370
371def mono_cam_box2vis(cam_box):

Callers 2

transformMethod · 0.90
voxel_sampleFunction · 0.90

Calls 1

catMethod · 0.45

Tested by

no test coverage detected