-
Notifications
You must be signed in to change notification settings - Fork 15
/
bin2pcd_folder.py
38 lines (31 loc) · 1011 Bytes
/
bin2pcd_folder.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
37
38
import numpy as np
import struct
import os
import sys
import open3d as o3d
def bin_to_pcd(binFileName):
size_float = 4
list_pcd = []
with open(binFileName, "rb") as f:
byte = f.read(size_float * 4)
while byte:
x, y, z, intensity = struct.unpack("ffff", byte)
list_pcd.append([x, y, z])
byte = f.read(size_float * 4)
np_pcd = np.asarray(list_pcd)
pcd = o3d.geometry.PointCloud()
pcd.points = o3d.utility.Vector3dVector(np_pcd)
return pcd
def main(binFolderName, pcdFolderName):
for i in os.listdir(binFolderName):
if not i.startswith('.'):
binFileName = binFolderName + '/' + i
print(i)
pcd = bin_to_pcd(binFileName)
pcdFileName = pcdFolderName+i[:-4]+'.pcd'
print(pcdFileName)
o3d.io.write_point_cloud(pcdFileName, pcd)
if __name__ == "__main__":
a = sys.argv[1]
b = sys.argv[2]
main(a, b)