"scripts/vscode:/vscode.git/clone" did not exist on "9b472bc91fd94c4b6858ddece4eb66013585457d"
indoor_loading.py 3.15 KB
Newer Older
1
import mmcv
liyinhao's avatar
liyinhao committed
2
3
import numpy as np

4
from mmdet.datasets.builder import PIPELINES
liyinhao's avatar
liyinhao committed
5
6


7
@PIPELINES.register_module()
8
9
class IndoorPointsColorNormalize(object):
    """Indoor Points Color Normalize
10
11
12
13
14
15
16
17
18
19
20

    Normalize color of the points.

    Args:
        color_mean (List[float]): Mean color of the point cloud.
    """

    def __init__(self, color_mean):
        self.color_mean = color_mean

    def __call__(self, results):
liyinhao's avatar
liyinhao committed
21
        points = results['points']
liyinhao's avatar
liyinhao committed
22
23
        assert points.shape[1] >= 6,\
            f'Expect points have channel >=6, got {points.shape[1]}'
24
25
26
27
        points[:, 3:6] = points[:, 3:6] - np.array(self.color_mean) / 256.0
        results['points'] = points
        return results

liyinhao's avatar
liyinhao committed
28
29
30
31
32
    def __repr__(self):
        repr_str = self.__class__.__name__
        repr_str += '(color_mean={})'.format(self.color_mean)
        return repr_str

33
34

@PIPELINES.register_module()
35
36
class IndoorLoadPointsFromFile(object):
    """Indoor Load Points From File.
liyinhao's avatar
liyinhao committed
37

liyinhao's avatar
liyinhao committed
38
    Load sunrgbd and scannet points from file.
liyinhao's avatar
liyinhao committed
39
40
41

    Args:
        use_height (bool): Whether to use height.
liyinhao's avatar
liyinhao committed
42
43
44
45
        load_dim (int): The dimension of the loaded points.
            Default: 6.
        use_dim (List[int]): Which dimensions of the points to be used.
            Default: [0, 1, 2].
liyinhao's avatar
liyinhao committed
46
47
    """

48
    def __init__(self, use_height, load_dim=6, use_dim=[0, 1, 2]):
liyinhao's avatar
liyinhao committed
49
        self.use_height = use_height
liyinhao's avatar
liyinhao committed
50
51
52
        assert max(use_dim) < load_dim, \
            f'Expect all used dimensions < {load_dim}, got {use_dim}'

liyinhao's avatar
liyinhao committed
53
54
        self.load_dim = load_dim
        self.use_dim = use_dim
liyinhao's avatar
liyinhao committed
55
56

    def __call__(self, results):
liyinhao's avatar
liyinhao committed
57
        pts_filename = results['pts_filename']
liyinhao's avatar
liyinhao committed
58
        mmcv.check_file_exist(pts_filename)
59
        points = np.load(pts_filename)
liyinhao's avatar
liyinhao committed
60
61
        points = points.reshape(-1, self.load_dim)
        points = points[:, self.use_dim]
liyinhao's avatar
liyinhao committed
62

liyinhao's avatar
liyinhao committed
63
        if self.use_height:
liyinhao's avatar
liyinhao committed
64
65
66
67
            floor_height = np.percentile(points[:, 2], 0.99)
            height = points[:, 2] - floor_height
            points = np.concatenate([points, np.expand_dims(height, 1)], 1)
        results['points'] = points
liyinhao's avatar
liyinhao committed
68
69
70
71
        return results

    def __repr__(self):
        repr_str = self.__class__.__name__
liyinhao's avatar
liyinhao committed
72
        repr_str += '(use_height={})'.format(self.use_height)
liyinhao's avatar
liyinhao committed
73
        repr_str += '(mean_color={})'.format(self.color_mean)
liyinhao's avatar
liyinhao committed
74
75
        repr_str += '(load_dim={})'.format(self.load_dim)
        repr_str += '(use_dim={})'.format(self.use_dim)
liyinhao's avatar
liyinhao committed
76
77
        return repr_str

liyinhao's avatar
liyinhao committed
78
79

@PIPELINES.register_module
80
81
class IndoorLoadAnnotations3D(object):
    """Indoor Load Annotations3D.
liyinhao's avatar
liyinhao committed
82

83
    Load instance mask and semantic mask of points.
liyinhao's avatar
liyinhao committed
84
85
86
87
88
89
    """

    def __init__(self):
        pass

    def __call__(self, results):
liyinhao's avatar
liyinhao committed
90
91
92
        pts_instance_mask_path = results['pts_instance_mask_path']
        pts_semantic_mask_path = results['pts_semantic_mask_path']

liyinhao's avatar
liyinhao committed
93
94
        mmcv.check_file_exist(pts_instance_mask_path)
        mmcv.check_file_exist(pts_semantic_mask_path)
liyinhao's avatar
liyinhao committed
95
96
97
98
        pts_instance_mask = np.load(pts_instance_mask_path)
        pts_semantic_mask = np.load(pts_semantic_mask_path)
        results['pts_instance_mask'] = pts_instance_mask
        results['pts_semantic_mask'] = pts_semantic_mask
liyinhao's avatar
liyinhao committed
99
100
101
102
103
104

        return results

    def __repr__(self):
        repr_str = self.__class__.__name__
        return repr_str