| 254 | return joint_img, joint_cam_wo_ra, joint_cam_ra, joint_valid, joint_trunc |
| 255 | |
| 256 | def process_db_coord_w_cam(joint_img, joint_cam, princpt, cam_trans, joint_valid, do_flip, img_shape, flip_pairs, |
| 257 | img2bb_trans, rot, src_joints_name, target_joints_name): |
| 258 | joint_img_original = joint_img.copy() |
| 259 | princpt_original = princpt.copy() |
| 260 | joint_img, joint_cam, joint_valid, princpt = joint_img.copy(), joint_cam.copy(), joint_valid.copy(), princpt.copy() |
| 261 | cam_trans_original = cam_trans.copy() |
| 262 | cam_trans = cam_trans.copy() |
| 263 | |
| 264 | # import ipdb;ipdb.set_trace() |
| 265 | |
| 266 | # flip augmentation |
| 267 | if do_flip: |
| 268 | joint_cam[:, 0] = -joint_cam[:, 0] |
| 269 | cam_trans[0] = -cam_trans[0] |
| 270 | joint_img[:, 0] = img_shape[1] - 1 - joint_img[:, 0] |
| 271 | princpt[0] = img_shape[1] - 1 - princpt[0] |
| 272 | for pair in flip_pairs: |
| 273 | joint_img[pair[0], :], joint_img[pair[1], :] = joint_img[pair[1], :].copy(), joint_img[pair[0], :].copy() |
| 274 | joint_cam[pair[0], :], joint_cam[pair[1], :] = joint_cam[pair[1], :].copy(), joint_cam[pair[0], :].copy() |
| 275 | joint_valid[pair[0], :], joint_valid[pair[1], :] = joint_valid[pair[1], :].copy(), joint_valid[pair[0], |
| 276 | :].copy() |
| 277 | |
| 278 | # 3D data rotation augmentation |
| 279 | rot_aug_mat = np.array([[np.cos(np.deg2rad(-rot)), -np.sin(np.deg2rad(-rot)), 0], |
| 280 | [np.sin(np.deg2rad(-rot)), np.cos(np.deg2rad(-rot)), 0], |
| 281 | [0, 0, 1]], dtype=np.float32) |
| 282 | joint_cam = np.dot(rot_aug_mat, joint_cam.transpose(1, 0)).transpose(1, 0) |
| 283 | |
| 284 | # affine transformation |
| 285 | joint_img_xy1 = np.concatenate((joint_img[:, :2], np.ones_like(joint_img[:, :1])), 1) |
| 286 | joint_img[:, :2] = np.dot(img2bb_trans, joint_img_xy1.transpose(1, 0)).transpose(1, 0) |
| 287 | joint_img[:, 0] = joint_img[:, 0] / cfg.input_img_shape[1] * cfg.output_hm_shape[2] |
| 288 | joint_img[:, 1] = joint_img[:, 1] / cfg.input_img_shape[0] * cfg.output_hm_shape[1] |
| 289 | |
| 290 | # do affine transformation to princpt |
| 291 | princpt_xy1 = np.concatenate((princpt[:2], np.ones_like(princpt[:1])), 0) |
| 292 | princpt[:2] = np.dot(img2bb_trans, princpt_xy1) |
| 293 | |
| 294 | # check truncation |
| 295 | joint_trunc = joint_valid * ((joint_img_original[:, 0] > 0) * (joint_img[:, 0] >= 0) * (joint_img[:, 0] < cfg.output_hm_shape[2]) * \ |
| 296 | (joint_img_original[:, 1] > 0) *(joint_img[:, 1] >= 0) * (joint_img[:, 1] < cfg.output_hm_shape[1]) * \ |
| 297 | (joint_img_original[:, 2] > 0) *(joint_img[:, 2] >= 0) * (joint_img[:, 2] < cfg.output_hm_shape[0])).reshape(-1, |
| 298 | 1).astype( |
| 299 | np.float32) |
| 300 | |
| 301 | # transform joints to target db joints |
| 302 | joint_img = transform_joint_to_other_db(joint_img, src_joints_name, target_joints_name) |
| 303 | joint_cam_wo_ra = transform_joint_to_other_db(joint_cam, src_joints_name, target_joints_name) |
| 304 | joint_valid = transform_joint_to_other_db(joint_valid, src_joints_name, target_joints_name) |
| 305 | joint_trunc = transform_joint_to_other_db(joint_trunc, src_joints_name, target_joints_name) |
| 306 | |
| 307 | # root-alignment, for joint_cam input wo ra |
| 308 | joint_cam_ra = joint_cam_wo_ra.copy() |
| 309 | joint_cam_ra = joint_cam_ra - joint_cam_ra[smpl_x.root_joint_idx, None, :] # root-relative |
| 310 | joint_cam_ra[smpl_x.joint_part['lhand'], :] = joint_cam_ra[smpl_x.joint_part['lhand'], :] - joint_cam_ra[ |
| 311 | smpl_x.lwrist_idx, None, |
| 312 | :] # left hand root-relative |
| 313 | joint_cam_ra[smpl_x.joint_part['rhand'], :] = joint_cam_ra[smpl_x.joint_part['rhand'], :] - joint_cam_ra[ |