| 218 | |
| 219 | |
| 220 | def process_human_model_output(human_model_param, cam_param, do_flip, img_shape, img2bb_trans, rot, human_model_type): |
| 221 | if human_model_type == 'smplx': |
| 222 | human_model = smpl_x |
| 223 | rotation_valid = np.ones((smpl_x.orig_joint_num), dtype=np.float32) |
| 224 | coord_valid = np.ones((smpl_x.joint_num), dtype=np.float32) |
| 225 | |
| 226 | root_pose, body_pose, shape, trans = human_model_param['root_pose'], human_model_param['body_pose'], \ |
| 227 | human_model_param['shape'], human_model_param['trans'] |
| 228 | if 'lhand_pose' in human_model_param and human_model_param['lhand_valid']: |
| 229 | lhand_pose = human_model_param['lhand_pose'] |
| 230 | else: |
| 231 | lhand_pose = np.zeros((3 * len(smpl_x.orig_joint_part['lhand'])), dtype=np.float32) |
| 232 | rotation_valid[smpl_x.orig_joint_part['lhand']] = 0 |
| 233 | coord_valid[smpl_x.joint_part['lhand']] = 0 |
| 234 | if 'rhand_pose' in human_model_param and human_model_param['rhand_valid']: |
| 235 | rhand_pose = human_model_param['rhand_pose'] |
| 236 | else: |
| 237 | rhand_pose = np.zeros((3 * len(smpl_x.orig_joint_part['rhand'])), dtype=np.float32) |
| 238 | rotation_valid[smpl_x.orig_joint_part['rhand']] = 0 |
| 239 | coord_valid[smpl_x.joint_part['rhand']] = 0 |
| 240 | if 'jaw_pose' in human_model_param and 'expr' in human_model_param and human_model_param['face_valid']: |
| 241 | jaw_pose = human_model_param['jaw_pose'] |
| 242 | expr = human_model_param['expr'] |
| 243 | expr_valid = True |
| 244 | else: |
| 245 | jaw_pose = np.zeros((3), dtype=np.float32) |
| 246 | expr = np.zeros((smpl_x.expr_code_dim), dtype=np.float32) |
| 247 | rotation_valid[smpl_x.orig_joint_part['face']] = 0 |
| 248 | coord_valid[smpl_x.joint_part['face']] = 0 |
| 249 | expr_valid = False |
| 250 | if 'gender' in human_model_param: |
| 251 | gender = human_model_param['gender'] |
| 252 | else: |
| 253 | gender = 'neutral' |
| 254 | root_pose = torch.FloatTensor(root_pose).view(1, 3) # (1,3) |
| 255 | body_pose = torch.FloatTensor(body_pose).view(-1, 3) # (21,3) |
| 256 | lhand_pose = torch.FloatTensor(lhand_pose).view(-1, 3) # (15,3) |
| 257 | rhand_pose = torch.FloatTensor(rhand_pose).view(-1, 3) # (15,3) |
| 258 | jaw_pose = torch.FloatTensor(jaw_pose).view(-1, 3) # (1,3) |
| 259 | shape = torch.FloatTensor(shape).view(1, -1) # SMPLX shape parameter |
| 260 | expr = torch.FloatTensor(expr).view(1, -1) # SMPLX expression parameter |
| 261 | trans = torch.FloatTensor(trans).view(1, -1) # translation vector |
| 262 | |
| 263 | # apply camera extrinsic (rotation) |
| 264 | # merge root pose and camera rotation |
| 265 | if 'R' in cam_param: |
| 266 | R = np.array(cam_param['R'], dtype=np.float32).reshape(3, 3) |
| 267 | root_pose = root_pose.numpy() |
| 268 | root_pose, _ = cv2.Rodrigues(root_pose) |
| 269 | root_pose, _ = cv2.Rodrigues(np.dot(R, root_pose)) |
| 270 | root_pose = torch.from_numpy(root_pose).view(1, 3) |
| 271 | |
| 272 | # get mesh and joint coordinates |
| 273 | zero_pose = torch.zeros((1, 3)).float() # eye poses |
| 274 | with torch.no_grad(): |
| 275 | output = smpl_x.layer[gender](betas=shape, body_pose=body_pose.view(1, -1), global_orient=root_pose, |
| 276 | transl=trans, left_hand_pose=lhand_pose.view(1, -1), |
| 277 | right_hand_pose=rhand_pose.view(1, -1), jaw_pose=jaw_pose.view(1, -1), |