-
Notifications
You must be signed in to change notification settings - Fork 21
/
pcd_vis.py
53 lines (42 loc) · 1.29 KB
/
pcd_vis.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import open3d as open3d
import numpy as np
def draw_pc(pc_xyzrgb):
"""
Plot pointcloud with color
Parameter:
pc_xyzrgb: [[x, y, z, r, g, b],...]
"""
pc = open3d.PointCloud()
pc.points = open3d.Vector3dVector(pc_xyzrgb[:, 0:3])
if pc_xyzrgb.shape[1] == 3:
open3d.draw_geometries([pc])
return 0
if np.max(pc_xyzrgb[:, 3:6]) > 20: ## 0-255
pc.colors = open3d.Vector3dVector(pc_xyzrgb[:, 3:6] / 255.)
else:
pc.colors = open3d.Vector3dVector(pc_xyzrgb[:, 3:6])
open3d.draw_geometries([pc])
return 0
def read_pcd(path):
"""
Read pcd file generated by ./func.py/save_pc
Parameter:
path: path of pcd file
Return:
xyzrgb: numpy array of colored pointcloud [[x, y, z. r, g, b], ...]
"""
xyzrgb = []
with open(path, 'r') as f:
content = f.readlines()
for i in content[10:]:
i_content = i.split(" ")
x, y, z = float(i_content[0]), float(i_content[1]), float(i_content[2])
r, g, b = float(i_content[3]), float(i_content[4]), float(i_content[5][:-1])
xyzrgb.append([x,y,z,r,g,b])
return np.array(xyzrgb)
if __name__ == "__main__":
PATH = "./result/pcd/xxxxxx.pcd"
# Read
pc = read_pcd(PATH)
# Draw
draw_pc(pc)