3D姿态估计结果可视化(利用自己的excel数据)

基本流程:

1.从excel中读取数据,并生成np数组。

2.利用np数组进行绘图

注意事项:

1.我的部分数据如下:共有21个关节点,每一行代表视频的一帧,以每三个数据为一组代表一个关节点。

 2.我的绘制的关节点关系如下:

 

代码如下:

import matplotlib.pyplot as plt
import numpy as np
import xlrd
list_one_frame=[]
list_all_frame=[]

# 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]]
'''
human36m_connectivity_dict =[[0,1,0],[1,2,0],[2,7,1],[2,3,0],[7,8,1],[3,4,0],[8,9,1],[4,5,0],[9,10,1],[5,6,0],
                             [7,16,1],[3,11,0],[16,17,1],[11,12,0],[17,18,1],[12,13,0],[18,20,1],[13,15,0],[19,20,1],[13,14,0],[16,11,0]]


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")


def get_file():
    path=r'C:\Users\liangshuwen\Desktop\homework\single_basketball.xlsx'
    Path = path.strip("\\u202a")
    data1 = xlrd.open_workbook(Path)
    table=data1.sheets()[0]
    n_rows=table.nrows#50
    n_cols=table.ncols#63
    num=int(n_cols/3)
    num2=int(n_rows/3)
    list_all_frame=[]
    for i in range(0,n_rows,1):#第i帧视频
        list_one_frame = []
        for j in range(0,n_cols,3):
            x = table.cell_value(rowx=i, colx=j)
            y = table.cell_value(rowx=i, colx=j+1)
            z = table.cell_value(rowx=i, colx=j + 2)
            temp = list_one_frame.append([x, y, z])
        list_all_frame.append(list_one_frame)
        i=i+2
    list_all_frame=np.array(list_all_frame)
    return  list_all_frame




if __name__ == '__main__':

    if __name__ == '__main__':
        list_all_frame=get_file()
        specific_3d_skeleton = list_all_frame
        fig = plt.figure()
        ax = fig.add_subplot(111, projection='3d')
        plt.ion()
        i = 0
        while i < specific_3d_skeleton.shape[0]:
            plt.cla()
            ax.set_xlim(left=-3000, right=1300)
            ax.set_zlim(0, 2000)
            ax.set_ylim(-500, 1000)
            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()

运行结果如下,为一个可拖拽的动图:

 

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值