-
Notifications
You must be signed in to change notification settings - Fork 4
/
visualizations.py
97 lines (76 loc) · 2.83 KB
/
visualizations.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
import os
import open3d as o3d
import seaborn as sns
def pc_to_pcd(pc):
palette_PC = sns.color_palette()
pcd = o3d.geometry.TriangleMesh.create_sphere(radius=0.008)
pcd.translate(pc[0])
pcd.paint_uniform_color(palette_PC[7])
''' Add points in the original point cloud'''
for i in range(len(pc)):
point = o3d.geometry.TriangleMesh.create_sphere(radius=0.008) ## 0.005
point.translate(pc[i])
point.paint_uniform_color(palette_PC[7])
pcd += point
return pcd
def kp_to_pcd(kp):
palette = sns.color_palette("bright")
palette_dark = sns.color_palette("dark")
pcd = o3d.geometry.TriangleMesh.create_sphere(radius=0.035)
pcd.translate(kp[0])
pcd.paint_uniform_color(palette[0])
for i in range(1, len(kp)):
point = o3d.geometry.TriangleMesh.create_sphere(radius=0.035) # ablation: 0.035, figures: 0.050
point.translate(kp[i])
if i == 7:
point.paint_uniform_color(palette_dark[7])
else:
point.paint_uniform_color(palette[i])
pcd += point
return pcd
def save_kp_and_pc_in_pcd(pc, kp, output_dir, save=True, name=""):
'''
Parameters
----------
points point cloud [2048, 3]
kp estimated key-points [10, 3]
both if plot both or just the point clouds
Returns show the key-points/point cloud
-------
'''
palette_PC = sns.color_palette()
palette = sns.color_palette("bright")
palette_dark = sns.color_palette("dark")
pcd = o3d.geometry.TriangleMesh.create_sphere(radius=0.008)
pcd.translate(pc[0])
pcd.paint_uniform_color(palette_PC[7])
''' Add points in the original point cloud'''
for i in range(len(pc)):
point = o3d.geometry.TriangleMesh.create_sphere(radius=0.008) ## 0.005
point.translate(pc[i])
point.paint_uniform_color(palette_PC[7])
pcd += point
''' Add Keypoitnts '''
for i in range(0, len(kp)):
point = o3d.geometry.TriangleMesh.create_sphere(radius=0.035) # ablation: 0.035, figures: 0.050
point.translate(kp[i])
if i==7:
point.paint_uniform_color(palette_dark[7])
else:
point.paint_uniform_color(palette[i])
pcd += point
if save:
if not os.path.exists(output_dir+'/ply'):
os.makedirs(output_dir+'/ply')
o3d.io.write_triangle_mesh("{}/{}.ply".format(output_dir+'/ply', name), pcd)
vis = o3d.visualization.Visualizer()
vis.create_window()
vis.add_geometry(pcd)
vis.poll_events()
vis.update_renderer()
if not os.path.exists(output_dir+'/png'):
os.makedirs(output_dir+'/png')
vis.capture_screen_image("{}/{}.png".format(output_dir+'/png', name))
vis.destroy_window()
else:
o3d.visualization.draw_geometries([pcd])