1. 程式人生 > 實用技巧 >PKU-MMD骨架資料視覺化程式,動態圖,python

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資料集中資料資料順序與各節點的對應關係如下圖所示。官網上沒給出這個對應關係,我通過視訊和資料散點圖之間來回核對,摸清了這個對應關係。

動態視覺化程式如下:

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

points = np.loadtxt('/Users/wangpeng/Desktop/PKU_MMD/Skeleton/0033-M.txt', 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])

# 相鄰各節點列表,用來畫節點之間的連線線
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 = 1000   # 到第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.xlim(xmin, xmax)
    plt.ylim(ymin, ymax)
    plt.pause(0.01)

plt.ioff()
plt.show()


# 3D展示------------------------------------------------------------------------
#n = 0   # 從第n幀開始展示
#m = 1000   # 到第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.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()

下面只展示第一幀: