如何解决从数值数据集中在 python 中绘制 3D 姿势骨架数据
我正在从事人体姿势预测项目,我需要根据数值数据集绘制人体 3D 姿势骨架,以比较地面实况和预测值。喜欢这张图片:enter image description here 我已经在使用这个简单的代码了,
ax = plt.axes(projection='3d')
fig = plt.figure()
fig = plt.figure()
xdata = np.array(data[values])
ydata = np.array(data[values])
zdata = np.array(data[values])
ax.scatter3D(xdata,ydata,zdata,c=zdata)
plt.show()
但它向我展示了 3D 图中的点,我知道它不正确,所以这里是问题: **有没有要调用的库或函数? (因为我已经使用了分散,我知道这是错误的) [我的数据集有 6395 行和 54 列,我正在寻找一种方法来显示例如每次或更少的 10 个不同的姿势。]
解决方法
import typing as tp
import numpy as np
import matplotlib.pyplot as plt
def get_chain_dots(
dots: np.ndarray,# shape == (n_dots,3)
chain_dots_indexes: tp.List[int],# length == n_dots_in_chain
# in continuous order,i.e.
# left_hand_ix >>> chest_ix >>> right_hand_ix
) -> np.ndarray: # chain of dots
"""Get continuous chain of dots
chain_dots_indexes -
indexes of points forming a continuous chain;
example of chain: [hand_l,elbow_l,shoulder_l,chest,shoulder_r,elbow_r,hand_r]
"""
return dots[chain_dots_indexes]
def get_chains(
dots: np.ndarray,3)
spine_chain_ixs: tp.List[int],# pelvis >>> chest >>> head
hands_chain_ixs: tp.List[int],# left_hand >>> chest >>> right_hand
legs_chain_ixs: tp.List[int] # left_leg >>> pelvis >>> right_leg
):
return (get_chain_dots(dots,spine_chain_ixs),get_chain_dots(dots,hands_chain_ixs),legs_chain_ixs))
def subplot_nodes(dots: np.ndarray,3)
ax):
return ax.scatter3D(*dots.T,c=dots[:,-1])
def subplot_bones(chains: tp.Tuple[np.ndarray,...],ax):
return [ax.plot(*chain.T) for chain in chains]
def plot_skeletons(
skeletons: tp.Sequence[np.ndarray],chains_ixs: tp.Tuple[tp.List[int],tp.List[int],tp.List[int]]):
fig = plt.figure()
for i,dots in enumerate(skeletons,start=1):
chains = get_chains(dots,*chains_ixs)
ax = fig.add_subplot(2,5,i,projection='3d')
subplot_nodes(dots,ax)
subplot_bones(chains,ax)
plt.show()
def test():
"""Plot random poses of simplest skeleton"""
skeletons = np.random.standard_normal(size=(10,11,3))
chains_ixs = ([0,1,2,3,4],# hand_l,hand_r
[5,6],# pelvis,head
[7,8,9,10]) # foot_l,knee_l,pelvis,knee_r,foot_r
plot_skeletons(skeletons,chains_ixs)
if __name__ == '__main__':
test()
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。