| 95 | return output_img |
| 96 | |
| 97 | class SMPLRender(): |
| 98 | def __init__(self, SMPL_MODEL_DIR): |
| 99 | self.device = 'cuda' |
| 100 | self.smpl = SMPL(SMPL_MODEL_DIR, |
| 101 | batch_size=1, |
| 102 | create_transl=False).to(self.device) |
| 103 | |
| 104 | self.focal_length = 5000 |
| 105 | |
| 106 | def render(self, image, smpl_param, is_headroot=False): |
| 107 | pose = smpl_param['pred_pose'] |
| 108 | if pose.size==72: |
| 109 | pose = pose.reshape(-1,3) |
| 110 | pose = RRR.from_rotvec(pose).as_matrix() |
| 111 | pose = pose.reshape(1,24,3,3) |
| 112 | pred_betas = torch.from_numpy(smpl_param['pred_shape'].reshape(1, 10).astype(np.float32)).to(self.device) |
| 113 | pred_rotmat = torch.from_numpy(pose.astype(np.float32)).to(self.device) |
| 114 | pred_camera_t = smpl_param['pred_root'].reshape(1, 3).astype(np.float32) |
| 115 | smpl_output = self.smpl(betas=pred_betas, body_pose=pred_rotmat[:, 1:], |
| 116 | global_orient=pred_rotmat[:, 0].unsqueeze(1), pose2rot=False) |
| 117 | |
| 118 | |
| 119 | vertices = smpl_output.vertices[0].detach().cpu().numpy() |
| 120 | pred_camera_t = pred_camera_t[0] |
| 121 | |
| 122 | if is_headroot: |
| 123 | pred_camera_t = pred_camera_t - smpl_output.joints[0,12].detach().cpu().numpy() |
| 124 | |
| 125 | renderer = Renderer(focal_length=self.focal_length, |
| 126 | img_res=(image.shape[1], image.shape[0]), faces=self.smpl.faces) |
| 127 | |
| 128 | renderImg = renderer(vertices, pred_camera_t.copy(), image / 255.0) |
| 129 | renderer.renderer.delete() |
| 130 | return renderImg |
no outgoing calls
no test coverage detected