Skip to content

Commit

Permalink
三维人体 smpl 模型
Browse files Browse the repository at this point in the history
  • Loading branch information
yangyun1 committed Jan 6, 2021
1 parent 73ab2ec commit e3a9ccc
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 28 deletions.
17 changes: 7 additions & 10 deletions smpl/smpl.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,13 @@
smpl = pickle._Unpickler(open("/Users/yang/models/basicmodel_f_lbs_10_207_0_v1.0.0.pkl", "rb"), encoding='latin1')
smpl = smpl.load() # smpl 是一个字典,关键的 key 如下:

"""
J_regressor: (24, 6890), 与 vertices (6890, 3) 相乘边得到 joints 位置 (24, 3)
f: (13776, 3),faces,我们说到 mesh 除了有 vertices 组成,还有一个 triangle list,每个 triangle 由三个 vertices index 组成
kintree_table: (2, 24),一般取第一行,这就是上面提到的每个点的父节点
weights: (6890, 24), blend weights, 定义了顶点受每个 joint 旋转矩阵影响的权重
shapedirs: (6890, 3, 10), 表示体型参数到 shape blend shape 的映射关系
posedirs: (6890, 3, 207), 表示姿势参数到 pose blend shape 的映射关系
v_template: (6890, 3), 人体基模版的 vertices
"""
# J_regressor: (24, 6890), 与 vertices (6890, 3) 相乘边得到 joints 位置 (24, 3)
# f: (13776, 3),faces,我们说到 mesh 除了有 vertices 组成,还有一个 triangle list,每个 triangle 由三个 vertices index 组成
# kintree_table: (2, 24),一般取第一行,这就是上面提到的每个点的父节点
# weights: (6890, 24), blend weights, 定义了顶点受每个 joint 旋转矩阵影响的权重
# shapedirs: (6890, 3, 10), 表示体型参数到 shape blend shape 的映射关系
# posedirs: (6890, 3, 207), 表示姿势参数到 pose blend shape 的映射关系
# v_template: (6890, 3), 人体基模版的 vertices

#============================ Part 1: 显示基模版 v_template 下的人体, 并设置 betas 和 poses 参数, 见论文 figure 3(a)
# render(smpl['v_template'], smpl['f'])
Expand Down Expand Up @@ -141,4 +139,3 @@
v = np.matmul(T, v_posed_homo.T.reshape([-1, 4, 1]))
v = v.reshape([-1, 4])[:,:3] # 由于是齐次矩阵,取前3列
util.render(v, smpl['f'])

20 changes: 2 additions & 18 deletions smpl/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,26 +16,10 @@
import trimesh
import pyrender
import numpy as np
import chumpy as ch

class Rodrigues(ch.Ch):
dterms = 'rt'

def compute_r(self):
return cv2.Rodrigues(self.rt.r)[0]

def compute_dr_wrt(self, wrt):
if wrt is self.rt:
return cv2.Rodrigues(self.rt.r)[1].T

def posemap(p):
if isinstance(p, np.ndarray):
p = p.ravel()[3:]
return np.concatenate([(cv2.Rodrigues(np.array(pp))[0]-np.eye(3)).ravel() for pp in p.reshape((-1,3))]).ravel()
if p.ndim != 2 or p.shape[1] != 3:
p = p.reshape((-1,3))
p = p[1:]
return ch.concatenate([(Rodrigues(pp)-ch.eye(3)).ravel() for pp in p]).ravel()
p = p.ravel()[3:] # 跳过根结点
return np.concatenate([(cv2.Rodrigues(np.array(pp))[0]-np.eye(3)).ravel() for pp in p.reshape((-1,3))]).ravel()

def render(vertices, faces):
vertex_colors = np.ones([vertices.shape[0], 4]) * [0.3, 0.3, 0.3, 0.9]
Expand Down

0 comments on commit e3a9ccc

Please sign in to comment.