hongxiaoy commited on
Commit
bc160aa
1 Parent(s): faa2674

Create preprocess_gt.py

Browse files
Files changed (1) hide show
  1. preprocess_gt.py +40 -0
preprocess_gt.py ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import numpy as np
3
+ from plyfile import PlyData
4
+ from tqdm import tqdm
5
+
6
+
7
+ def preprocess(gt_path, save_path):
8
+ """Preprocess the CompleteScanNet dataset gt labels.
9
+
10
+ Args:
11
+ gt_path (str): Path to `CompleteScanNet_GT` directory.
12
+ save_path (str): Path where the preprocessed gt labels to be saved. The preprocessed labels
13
+ is a ndarray each with shape (N, 7), N is for voxels number, 7 is for [x, y, z, r, g, b, label].
14
+ """
15
+ os.makedirs(save_path, exist_ok=True)
16
+ ply_paths = os.listdir(gt_path)
17
+ for p in tqdm(ply_paths, desc="Preprocessing gt labels: ", colour='green'):
18
+ pth = os.path.join(gt_path, p)
19
+
20
+ ply_data = PlyData.read(pth)
21
+ vertex = ply_data['vertex']
22
+ new_xs = np.array(vertex['z'])
23
+ new_ys = np.array(vertex['x'])
24
+ new_zs = np.array(vertex['y'])
25
+ new_rs = np.array(vertex['red'])
26
+ new_gs = np.array(vertex['green'])
27
+ new_bs = np.array(vertex['blue'])
28
+ new_labels = np.array(vertex['label'])
29
+ voxels = np.stack([new_xs, new_ys, new_zs, new_rs, new_gs, new_bs, new_labels], axis=1)
30
+
31
+ filename = os.path.join(save_path, p)
32
+ filename = filename.replace('ply', 'npy')
33
+ with open(filename, 'wb') as fp:
34
+ np.save(fp, voxels)
35
+
36
+
37
+ if __name__ == "__main__":
38
+ gt = os.getenv["COMPLETE_SCANNET_GT_PATH"]
39
+ preprocessed = os.getenv["COMPLETE_SCANNET_PREPROCESS_PATH"]
40
+ preprocess(gt, preprocessed)