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