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

Class ConvertRGBDToPoints

embodiedscan/datasets/transforms/points.py:12–81  ·  view source on GitHub ↗

Convert depth map to point clouds. Args: coord_type (str): The type of point coordinates. Defaults to 'CAMERA'. use_color (bool): Whether to use color as additional features when converting the image to points. Generally speaking, if False, only return xy

Source from the content-addressed store, hash-verified

10
11@TRANSFORMS.register_module()
12class ConvertRGBDToPoints(BaseTransform):
13 """Convert depth map to point clouds.
14
15 Args:
16 coord_type (str): The type of point coordinates. Defaults to 'CAMERA'.
17 use_color (bool): Whether to use color as additional features
18 when converting the image to points. Generally speaking, if False,
19 only return xyz points. Otherwise, return xyzrgb points.
20 Defaults to False.
21 """
22
23 def __init__(self,
24 coord_type: str = 'CAMERA',
25 use_color: bool = False) -> None:
26 assert coord_type in ['CAMERA', 'LIDAR', 'DEPTH']
27 self.coord_type = coord_type
28 self.use_color = use_color
29
30 def transform(self, input_dict: dict) -> dict:
31 """Call function to normalize color of points.
32
33 Args:
34 input_dict (dict): Result dict containing point clouds data.
35
36 Returns:
37 dict: The result dict containing the normalized points.
38 Updated key and value are described below.
39
40 - points (:obj:`BasePoints`): Points after color normalization.
41 """
42 depth_img = input_dict['depth_img']
43 depth_cam2img = input_dict['depth_cam2img']
44 ws = np.arange(depth_img.shape[1])
45 hs = np.arange(depth_img.shape[0])
46 us, vs = np.meshgrid(ws, hs)
47 grid = np.stack(
48 [us.astype(np.float32),
49 vs.astype(np.float32), depth_img], axis=-1).reshape(-1, 3)
50 nonzero_indices = depth_img.reshape(-1).nonzero()[0]
51 grid3d = points_img2cam(grid, depth_cam2img)
52 points = grid3d[nonzero_indices]
53
54 attribute_dims = None
55 if self.use_color:
56 img = input_dict['img']
57 h, w = img.shape[0], img.shape[1]
58 cam2img = input_dict['cam2img']
59 points2d = np.round(points_cam2img(points,
60 cam2img)).astype(np.int32)
61 us = np.clip(points2d[:, 0], a_min=0, a_max=w - 1)
62 vs = np.clip(points2d[:, 1], a_min=0, a_max=h - 1)
63 rgb_points = img[vs, us]
64 points = np.concatenate([points, rgb_points], axis=-1)
65
66 if attribute_dims is None:
67 attribute_dims = dict()
68 attribute_dims.update(
69 dict(color=[

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected