-
Notifications
You must be signed in to change notification settings - Fork 34
/
show_3d_pose.py
73 lines (53 loc) · 1.97 KB
/
show_3d_pose.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
import numpy as np
import matplotlib.pyplot as plt
from utils import DLT
plt.style.use('seaborn')
pose_keypoints = np.array([16, 14, 12, 11, 13, 15, 24, 23, 25, 26, 27, 28])
def read_keypoints(filename):
fin = open(filename, 'r')
kpts = []
while(True):
line = fin.readline()
if line == '': break
line = line.split()
line = [float(s) for s in line]
line = np.reshape(line, (len(pose_keypoints), -1))
kpts.append(line)
kpts = np.array(kpts)
return kpts
def visualize_3d(p3ds):
"""Now visualize in 3D"""
torso = [[0, 1] , [1, 7], [7, 6], [6, 0]]
armr = [[1, 3], [3, 5]]
arml = [[0, 2], [2, 4]]
legr = [[6, 8], [8, 10]]
legl = [[7, 9], [9, 11]]
body = [torso, arml, armr, legr, legl]
colors = ['red', 'blue', 'green', 'black', 'orange']
from mpl_toolkits.mplot3d import Axes3D
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
for framenum, kpts3d in enumerate(p3ds):
if framenum%2 == 0: continue #skip every 2nd frame
for bodypart, part_color in zip(body, colors):
for _c in bodypart:
ax.plot(xs = [kpts3d[_c[0],0], kpts3d[_c[1],0]], ys = [kpts3d[_c[0],1], kpts3d[_c[1],1]], zs = [kpts3d[_c[0],2], kpts3d[_c[1],2]], linewidth = 4, c = part_color)
#uncomment these if you want scatter plot of keypoints and their indices.
# for i in range(12):
# #ax.text(kpts3d[i,0], kpts3d[i,1], kpts3d[i,2], str(i))
# #ax.scatter(xs = kpts3d[i:i+1,0], ys = kpts3d[i:i+1,1], zs = kpts3d[i:i+1,2])
#ax.set_axis_off()
ax.set_xticks([])
ax.set_yticks([])
ax.set_zticks([])
ax.set_xlim3d(-10, 10)
ax.set_xlabel('x')
ax.set_ylim3d(-10, 10)
ax.set_ylabel('y')
ax.set_zlim3d(-10, 10)
ax.set_zlabel('z')
plt.pause(0.1)
ax.cla()
if __name__ == '__main__':
p3ds = read_keypoints('kpts_3d.dat')
visualize_3d(p3ds)