-
Notifications
You must be signed in to change notification settings - Fork 0
/
visualize_face_in_world.py
70 lines (65 loc) · 2.28 KB
/
visualize_face_in_world.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
"""visualize canonical_face_model in world coordinate system
"""
from src.face_3d import get_face3d, get_face3d_14, get_cube_pts
import matplotlib.pyplot as plt
if __name__ == "__main__":
object_pts = get_face3d()
object_14 = get_face3d_14()
# figure setup
fig = plt.figure()
ax = fig.add_subplot(projection='3d')
ax.set_xlim3d(-10, 10)
ax.set_ylim3d(-10, 10)
ax.set_zlim3d(-10, 10)
ax.set_xlabel("x")
ax.set_ylabel("y")
ax.set_zlabel("z")
# origin
origin = (0, 0, 0)
xaxis = (1, 0, 0)
yaxis = (0, 1, 0)
zaxis = (0, 0, 1)
ax.scatter3D(origin[0], origin[1], origin[2], c='blue')
## x-axis
ax.quiver(origin[0], origin[1], origin[2], xaxis[0], xaxis[1], xaxis[2], length=1, normalize=True, color='b')
## y-axis
ax.quiver(origin[0], origin[1], origin[2], yaxis[0], yaxis[1], yaxis[2], length=1, normalize=True, color='g')
## z-axis
ax.quiver(origin[0], origin[1], origin[2], zaxis[0], zaxis[1], zaxis[2], length=1, normalize=True, color='r')
# face in world
## all pts(58)
ax.scatter3D(object_pts[:, 0], object_pts[:, 1], object_pts[:, 2], c='black')
## selected 14 pts
ax.scatter3D(object_14[:, 0], object_14[:, 1], object_14[:, 2], c='red', s=50)
## add text
for idx, pt in enumerate(object_14):
ax.text(pt[0], pt[1], pt[2], f"{idx}")
# cube here
# get (xmin, xmax), (ymin, ymax), (zmin, zmax)
xmin, xmax, ymin, ymax, zmin, zmax = get_cube_pts()
ax.plot3D([xmin, xmax, xmax, xmin, xmin],
[ymin, ymin, ymax, ymax, ymin],
[zmin, zmin, zmin, zmin, zmin],
c='b'
)
ax.plot3D([xmin, xmax, xmax, xmin, xmin],
[ymin, ymin, ymax, ymax, ymin],
[zmax, zmax, zmax, zmax, zmax],
c='b')
ax.plot3D([xmin, xmin],
[ymin, ymin],
[zmin, zmax],
c='b')
ax.plot3D([xmax, xmax],
[ymin, ymin],
[zmin, zmax],
c='b')
ax.plot3D([xmin, xmin],
[ymax, ymax],
[zmin, zmax],
c='b')
ax.plot3D([xmax, xmax],
[ymax, ymax],
[zmin, zmax],
c='b')
plt.show()