PKU-MMD骨架數據可視化程序,動態圖,python


PKU-MMD數據集簡介

官網鏈接:https://www.icst.pku.edu.cn/struct/Projects/PKUMMD.html

除官網提供的一些信息外,下面我再補充兩點信息。

補充信息1

各條視頻的長度,如下表,第一條視頻有4674幀,第二條視頻有4049幀。每一個view有359條視頻,總共有1825266幀,平均每個視頻有約5070幀。下表中的最后一個數字0是為了畫表格而隨手加上去的。

補充信息2

第一個視頻的第一幀中,第一個人的骨架節點坐標,第一列表示x坐標,第二列表示y坐標,第三列表示z坐標:

骨架數據可視化

PKU-MMD數據集中數據數據順序與各節點的對應關系如下圖所示。官網上沒給出這個對應關系,我通過視頻和數據散點圖之間來回核對,摸清了這個對應關系。

圖中的骨架各節點的連接方式是通過看原論文(PKU-MMD: A Large Scale Benchmark for Continuous Multi-Modal Human Action Understanding)而畫出來的,但我最近看到另外一篇論文(A Deep Learning Approach for Human Action Recognition using Skeletal Information)的畫法:

這兩種畫法唯一的區別在手部,后者似乎更合理。但為了和原論文吻合,下面的可視化程序采用的是前者。

動態可視化程序如下:

import os
import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D

file_name = '0017-M.txt'
points = np.loadtxt(os.path.join('/Users/wangpeng/Desktop/PKU_MMD/Skeleton', file_name), dtype=np.float)
row = points.shape[0]
point = (points[:, :75]).reshape(row, 25, 3)
xmax = np.max(point[:, :, 0])
xmin = np.min(point[:, :, 0])
ymax = np.max(point[:, :, 1])
ymin = np.min(point[:, :, 1])
zmax = np.max(point[:, :, 2])
zmin = np.min(point[:, :, 2])

# 讀取標簽
num_classes = 52   # number of classes
gt_array = np.loadtxt(os.path.join('/Users/wangpeng/Desktop/PKU_MMD/Label', file_name), dtype=np.int, delimiter=',')
label = np.ones([row, ], dtype=np.int) * (num_classes - 1)   # 0~50th is the original ground truth. The 51st class is the background.
for i in range(gt_array.shape[0]):
    label[gt_array[i, 1]-1: gt_array[i, 2]-1] = gt_array[i, 0] - 1   # 末尾的-1是為了讓標簽從0開始

# 相鄰各節點列表,用來畫節點之間的連接線
arm = [21, 7, 6, 5, 4, 20, 8, 9, 10, 11, 23]
rightHand = [22, 7]
leftHand = [24, 11]
bodyLeg = [3, 2, 20, 1, 0, 12, 13, 14, 15]
leftLeg = [0, 16, 17, 18, 19]

# 2D展示------------------------------------------------------------------------
n = 0   # 從第n幀開始展示
m = 1   # 到第m幀結束,n<m<row
plt.figure()
plt.ion()
for i in range(n, m):
    plt.cla()
    plt.scatter(point[i, :, 0], point[i, :, 1], c='red', s=40.0)
    plt.plot(point[i, arm, 0], point[i, arm, 1], c='green', lw=2.0)
    plt.plot(point[i, rightHand, 0], point[i, rightHand, 1], c='green', lw=2.0)
    plt.plot(point[i, leftHand, 0], point[i, leftHand, 1], c='green', lw=2.0)
    plt.plot(point[i, bodyLeg, 0], point[i, bodyLeg, 1], c='green', lw=2.0)
    plt.plot(point[i, leftLeg, 0], point[i, leftLeg, 1], c='green', lw=2.0)
    plt.text(xmax-0.8, ymax-0.2, 'frame: {}/{}'.format(i, row))
    plt.text(xmax-0.8, ymax-0.4, 'label: ' + str(label[i]))
    plt.xlim(xmin, xmax)
    plt.ylim(ymin, ymax)
    plt.pause(0.01)

plt.ioff()
plt.show()


# 3D展示------------------------------------------------------------------------
#n = 1100   # 從第n幀開始展示
#m = 1200   # 到第m幀結束,n<m<row
#fig = plt.figure()   # 先生成一塊畫布,然后在畫布上添加3D坐標軸
#plt.ion()
#for i in range(n, m):
#    fig.clf()
#    ax = Axes3D(fig)
#    ax.scatter(point[i, :, 0], point[i, :, 1], point[i, :, 2], c='red', s=40.0)
#    ax.plot(point[i, arm, 0], point[i, arm, 1], point[i, arm, 2], c='green', lw=2.0)
#    ax.plot(point[i, rightHand, 0], point[i, rightHand, 1], point[i, rightHand, 2], c='green', lw=2.0)
#    ax.plot(point[i, leftHand, 0], point[i, leftHand, 1], point[i, leftHand, 2], c='green', lw=2.0)
#    ax.plot(point[i, bodyLeg, 0], point[i, bodyLeg, 1], point[i, bodyLeg, 2], c='green', lw=2.0)
#    ax.plot(point[i, leftLeg, 0], point[i, leftLeg, 1], point[i, leftLeg, 2], c='green', lw=2.0)
#    ax.text(xmax-0.8, ymax-0.2, zmax-0.2, 'frame {}/{}'.format(i, row))
#    ax.text(xmax-0.8, ymax-0.4, zmax-0.4, 'label: ' + str(label[i]))
#    ax.set_xlabel("X")
#    ax.set_ylabel("Y")
#    ax.set_zlabel("Z")
#    ax.set_xlim(xmin, xmax)
#    ax.set_ylim(ymin, ymax)
#    ax.set_zlim(zmin, zmax)
#    plt.pause(0.01)
#
#plt.ioff()
#plt.show()

下面只展示第一幀:

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM