python matplotlib 绘制h36m 3D骨架

本文介绍了一种使用matplotlib和numpy库在Python中绘制3D人体骨架的方法,通过定义特定的人体关节连接顺序,实现静态和动画形式的人体姿态估计可视化。提供了具体的代码示例,包括如何设置坐标轴范围、绘制关节连线以及创建动画。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

静态

在这里插入图片描述

动画

在这里插入图片描述

静态
import matplotlib.pyplot as plt
import numpy as np

# h36m骨架连接顺序,每个骨架三个维度,分别为:起始关节,终止关节,左右关节标识(1 left 0 right)
human36m_connectivity_dict = [[0, 1, 0], [1, 2, 0], [2, 6, 0], [5, 4, 1], [4, 3, 1], [3, 6, 1], [6, 7, 0],
                              [7, 8, 0], [8, 16, 0], [9, 16, 0],
                              [8, 12, 0], [11, 12, 0], [10, 11, 0], [8, 13, 1], [13, 14, 1], [14, 15, 1]]


def draw3Dpose(pose_3d, ax, lcolor="#3498db", rcolor="#e74c3c", add_labels=False):  # blue, orange
    for i in human36m_connectivity_dict:
        x, y, z = [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 = 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_zlim3d([0, 2 * RADIUS + zroot])
    ax.set_ylim3d([-RADIUS + yroot, RADIUS + yroot])

    ax.set_xlabel("x")
    ax.set_ylabel("y")
    ax.set_zlabel("z")


if __name__ == '__main__':
    specific_3d_skeleton = np.array([[-60.70762, 403.8008, 109.0549],
                                     [-21.792213, 350.7608, 542.72705],
                                     [19.21995, 377.59323, 992.2105],
                                     [306.85883, 326.98297, 967.81555],
                                     [280.36816, 338.44727, 516.5916],
                                     [255.34781, 397.92474, 82.73034],
                                     [163.04, 352.288, 980.013],
                                     [178.85904, 334.66092, 1240.1534],
                                     [187.37048, 291.85312, 1487.3542],
                                     [150.81487, 211.43636, 1683.0452],
                                     [-384.66232, 412.21793, 1211.5632],
                                     [-168.92372, 486.90985, 1298.1694],
                                     [34.860744, 360.55948, 1461.1226],
                                     [353.3462, 285.74405, 1454.4487],
                                     [610.2841, 259.90445, 1322.6831],
                                     [778.4938, 93.56336, 1262.1969],
                                     [164.2095, 206.31268, 1568.9426]])

    fig = plt.figure()
    ax = fig.add_subplot(111, projection='3d')
    draw3Dpose(specific_3d_skeleton, ax)
    plt.show()

动画 3d_pose.npy下载 mega |||| 3d_pose.npy下载 百度云(提取码: uxnc)
if __name__ == '__main__':
    specific_3d_skeleton = np.load('3d_pose.npy')
    fig = plt.figure()
    ax = fig.add_subplot(111, projection='3d')
    plt.ion()
    i = 0
    while i < specific_3d_skeleton.shape[0]:
        ax.lines = []
        draw3Dpose(specific_3d_skeleton[i], ax)
        # print(time.time() - t)
        plt.pause(0.001)
        i += 1
        if i == specific_3d_skeleton.shape[0]:
            i = 0
    plt.ioff()
    plt.show()
评论 27
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值