从一个博客参考
我使用的数据集只有骨骼数据(三维坐标)
def draw3Dpose(pose_3d, ax, lcolor="#3498db", rcolor="#e74c3c", add_labels=False): # blue, orange
# 骨架连接顺序:起始关节,终止关节,左右关节标识(1 left 0 right)
IRDS_connect_dict = [[0, 16, 0], [16, 17, 0], [17, 18, 0], [18, 19, 0], [0, 12, 1], [12, 13, 1], [13, 14, 1],
[14, 15, 1], [0, 1, 0], [1, 20, 0], [20, 2, 1], [2, 3, 1], [20, 8, 0], [8, 9, 0], [9, 10, 0],
[10, 11, 0],
[11, 24, 0], [11, 23, 0], [20, 4, 1], [4, 5, 1], [5, 6, 1], [6, 7, 1], [7, 22, 1], [7, 21, 1]]
# for i in human36m_connectivity_dict:
for i in IRDS_connect_dict:
x, z, y = [np.array([pose_3d[i[0], j], pose_3d[i[1], j]]) for j in range(3)]
ax.plot(x, y, z, lw=2, c=lcolor if i[2] else rcolor)
RADIUS = 0.750 # space around the subject
xroot, yroot, zroot = pose_3d[5, 0], pose_3d[5, 1], pose_3d[5, 2]
ax.set_xlim3d([-RADIUS + xroot, RADIUS + xroot])
ax.set_ylim3d([0, 2 * RADIUS + zroot])
ax.set_zlim3d([-RADIUS + yroot, RADIUS + yroot])
ax.set_xlabel("x")
ax.set_ylabel("y")
ax.set_zlabel("z")
def view_skeleton(path):
"""处理数据,变成[frame,pointsnum,3]格式"""
specific_3d_skeleton = np.loadtxt(path, dtype=np.float, encoding='utf-8', delimiter=',')
new_specific_3d_skeleton = []
for i in range(len(specific_3d_skeleton)):
frame = []
frame = np.reshape(specific_3d_skeleton[i], (25, 3))
new_specific_3d_skeleton.append(frame)
new_specific_3d_skeleton = np.array(new_specific_3d_skeleton)
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
plt.ion()#展示多图
i = 0
#死循环,一直展示动图
while i < new_specific_3d_skeleton.shape[0]:
ax.lines = []
draw3Dpose(new_specific_3d_skeleton[i], ax)
plt.pause(0.001)
i += 1
if i == new_specific_3d_skeleton.shape[0]:
i = 0
plt.ioff()
plt.show()
if __name__ == '__main__':
""" after feedback action replay """
pat_action = r'E:\pythonFile\myrehab\standard\0\101_18_0_4_1_stand.txt'
view_skeleton(pat_action)
print("...end...")
骨架连接顺序以及xyz轴可根据自己数据进行调整
如我刚开始用别人的代码画出来的人物是躺着而不是站着,调整坐标轴即可