-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathpreprocessing.py
More file actions
70 lines (58 loc) · 1.88 KB
/
preprocessing.py
File metadata and controls
70 lines (58 loc) · 1.88 KB
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import os
import numpy as np
import argparse
from utils.pts import read_pts
from utils.ply import dict2ply
PATH_PREPROCESSED = "data/preprocessed"
def center(coords):
means = np.mean(coords, axis=0)
centered = coords - means
return centered
def preprocess_pts(path, centering, scale):
print(f"Reading points from {path}")
data_pts = read_pts(path)
# center/scale point cloud
coords = data_pts[:, :3]
features = data_pts[:, 3:-1].astype(np.uint8)
labels = data_pts[:, -1].astype(np.uint8)
if centering:
coords = center(coords)
coords = (coords * scale).astype(np.float32)
data_ply = {
"x": coords[:, 0],
"y": coords[:, 1],
"z": coords[:, 2],
"intensity": features[:, 0],
"return_number": features[:, 1],
"number_of_returns": features[:, 2],
"labels": labels,
}
# save preprocessed point cloud
os.makedirs(PATH_PREPROCESSED, exist_ok=True)
filename = os.path.split(path)[-1].split(".")[-2]
path_ply = os.path.join(PATH_PREPROCESSED, filename + ".ply")
if dict2ply(data_ply, path_ply):
print(f"PLY point cloud successfully saved to {path_ply}")
if __name__ == "__main__":
parser = argparse.ArgumentParser(
description="Center and rescale point cloud"
)
parser.add_argument(
"--files", "-f", type=str, nargs="+", help="Path to point cloud file"
)
parser.add_argument(
"--scale", "-s", type=float, default=1, help="Scale factor"
)
parser.add_argument(
"--centering",
"-c",
action="store_true",
help="Recenter point cloud coordinates",
)
args = parser.parse_args()
# Path of the file
# Load point cloud
print(f"Centering : {args.centering}")
print(f"Scale factor : {args.scale}")
for path in args.files:
preprocess_pts(path, args.centering, args.scale)