(path, info_dict, white_background, image_scaling=0.5, return_smplx=False)
| 265 | return scene_info |
| 266 | |
| 267 | def readCamerasDNARendering(path, info_dict, white_background, image_scaling=0.5, return_smplx=False): |
| 268 | output_view = info_dict["views"] |
| 269 | frame_idx = info_dict["frame_idx"] |
| 270 | ratio = image_scaling |
| 271 | |
| 272 | cam_infos = [] |
| 273 | main_file = path |
| 274 | annot_file = path.replace('main', 'annotations').split('.')[0] + '_annots.smc' |
| 275 | main_reader = SMCReader(main_file) |
| 276 | annot_reader = SMCReader(annot_file) |
| 277 | |
| 278 | smplx_vertices = None |
| 279 | if return_smplx: |
| 280 | gender = main_reader.actor_info['gender'] |
| 281 | model = SMPLX( |
| 282 | 'assets/body_models/smplx/', smpl_type='smplx', |
| 283 | gender=gender, use_face_contour=True, flat_hand_mean=False, use_pca=False, |
| 284 | num_betas=10, num_expression_coeffs=10, ext='npz' |
| 285 | ) |
| 286 | smplx_dict = annot_reader.get_SMPLx(Frame_id=frame_idx) |
| 287 | betas = torch.from_numpy(smplx_dict["betas"]).unsqueeze(0).float() |
| 288 | expression = torch.from_numpy(smplx_dict["expression"]).unsqueeze(0).float() |
| 289 | fullpose = torch.from_numpy(smplx_dict["fullpose"]).unsqueeze(0).float() |
| 290 | translation = torch.from_numpy(smplx_dict['transl']).unsqueeze(0).float() |
| 291 | output = model( |
| 292 | betas=betas, |
| 293 | expression=expression, |
| 294 | global_orient = fullpose[:, 0].clone(), |
| 295 | body_pose = fullpose[:, 1:22].clone(), |
| 296 | jaw_pose = fullpose[:, 22].clone(), |
| 297 | leye_pose = fullpose[:, 23].clone(), |
| 298 | reye_pose = fullpose[:, 24].clone(), |
| 299 | left_hand_pose = fullpose[:, 25:40].clone(), |
| 300 | right_hand_pose = fullpose[:, 40:55].clone(), |
| 301 | transl = translation, |
| 302 | return_verts=True) |
| 303 | smplx_vertices = output.vertices.detach().cpu().numpy().squeeze() |
| 304 | |
| 305 | parent_dir = os.path.dirname(os.path.dirname(path)) |
| 306 | out_img_dir = os.path.join(parent_dir, "images") |
| 307 | # os.makedirs(out_img_dir, exist_ok=True) |
| 308 | bg = np.array([255, 255, 255]) if white_background else np.array([0, 0, 0]) |
| 309 | idx = 0 |
| 310 | for view_index in output_view: |
| 311 | # Load K, R, T |
| 312 | cam_params = annot_reader.get_Calibration(view_index) |
| 313 | K = cam_params['K'] |
| 314 | D = cam_params['D'] # k1, k2, p1, p2, k3 |
| 315 | RT = cam_params['RT'] |
| 316 | |
| 317 | # Load image, mask |
| 318 | image = main_reader.get_img('Camera_5mp', view_index, Image_type='color', Frame_id=frame_idx) |
| 319 | image = cv2.undistort(image, K, D) |
| 320 | image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB) |
| 321 | |
| 322 | mask = annot_reader.get_mask(view_index, Frame_id=frame_idx) |
| 323 | mask = cv2.undistort(mask, K, D) |
| 324 | mask = mask[..., np.newaxis].astype(np.float32) / 255.0 |
no test coverage detected