-
Notifications
You must be signed in to change notification settings - Fork 34
/
Copy pathpcd2bin.py
37 lines (32 loc) · 1.08 KB
/
pcd2bin.py
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
import os
import numpy as np
import fire
def read_pcd(filepath):
lidar = []
with open(filepath,'r') as f:
line = f.readline().strip()
while line:
linestr = line.split(" ")
if len(linestr) == 4:
linestr_convert = list(map(float, linestr))
lidar.append(linestr_convert)
line = f.readline().strip()
return np.array(lidar)
def convert(pcdfolder, binfolder):
current_path = os.getcwd()
ori_path = os.path.join(current_path, pcdfolder)
file_list = os.listdir(ori_path)
des_path = os.path.join(current_path, binfolder)
if os.path.exists(des_path):
pass
else:
os.makedirs(des_path)
for file in file_list:
(filename,extension) = os.path.splitext(file)
velodyne_file = os.path.join(ori_path, filename) + '.pcd'
pl = read_pcd(velodyne_file)
pl = pl.reshape(-1, 4).astype(np.float32)
velodyne_file_new = os.path.join(des_path, filename) + '.bin'
pl.tofile(velodyne_file_new)
if __name__ == "__main__":
fire.Fire()