forked from axinc-ai/ailia-models
-
Notifications
You must be signed in to change notification settings - Fork 0
/
points_utils.py
76 lines (67 loc) · 1.87 KB
/
points_utils.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
import numpy as np
def plot_lines(
ax,
points,
connections,
dimension,
lw=4,
c='k',
linestyle='-',
alpha=0.8,
add_index=False):
"""
Plot 2D/3D lines given points and connection.
connections are of shape [n_lines, 2]
"""
if add_index:
for idx in range(len(points)):
if dimension == 2:
x, y = points[idx][0], points[idx][1]
ax.text(x, y, str(idx))
elif dimension == 3:
x, y, z = points[idx][0], points[idx][1], points[idx][2]
ax.text(x, y, z, str(idx))
connections = connections.reshape(-1, 2)
for connection in connections:
x = [points[connection[0]][0], points[connection[1]][0]]
y = [points[connection[0]][1], points[connection[1]][1]]
if dimension == 3:
z = [points[connection[0]][2], points[connection[1]][2]]
line, = ax.plot(x, y, z, lw=lw, c=c, linestyle=linestyle, alpha=alpha)
else:
line, = ax.plot(x, y, lw=lw, c=c, linestyle=linestyle, alpha=alpha)
return line
def plot_3d_bbox(
ax,
bbox_3d_projected,
color=None,
linestyle='-',
add_index=False):
"""
Draw the projected edges of a 3D cuboid.
"""
c = np.random.rand(3) if color is None else color
plot_lines(
ax,
bbox_3d_projected,
plot_3d_bbox.connections,
dimension=2,
c=c,
linestyle=linestyle,
add_index=add_index
)
return
## static variables implemented as function attributes
plot_3d_bbox.connections = np.array(
[[0, 1],
[0, 2],
[1, 3],
[2, 3],
[4, 5],
[5, 7],
[4, 6],
[6, 7],
[0, 4],
[1, 5],
[2, 6],
[3, 7]])