| 8 | |
| 9 | |
| 10 | def coco_h36m(keypoints): |
| 11 | temporal = keypoints.shape[0] |
| 12 | keypoints_h36m = np.zeros_like(keypoints, dtype=np.float32) |
| 13 | htps_keypoints = np.zeros((temporal, 4, 2), dtype=np.float32) |
| 14 | |
| 15 | # htps_keypoints: head, thorax, pelvis, spine |
| 16 | htps_keypoints[:, 0, 0] = np.mean(keypoints[:, 1:5, 0], axis=1, dtype=np.float32) |
| 17 | htps_keypoints[:, 0, 1] = np.sum(keypoints[:, 1:3, 1], axis=1, dtype=np.float32) - keypoints[:, 0, 1] |
| 18 | htps_keypoints[:, 1, :] = np.mean(keypoints[:, 5:7, :], axis=1, dtype=np.float32) |
| 19 | htps_keypoints[:, 1, :] += (keypoints[:, 0, :] - htps_keypoints[:, 1, :]) / 3 |
| 20 | |
| 21 | htps_keypoints[:, 2, :] = np.mean(keypoints[:, 11:13, :], axis=1, dtype=np.float32) |
| 22 | htps_keypoints[:, 3, :] = np.mean(keypoints[:, [5, 6, 11, 12], :], axis=1, dtype=np.float32) |
| 23 | |
| 24 | keypoints_h36m[:, spple_keypoints, :] = htps_keypoints |
| 25 | keypoints_h36m[:, h36m_coco_order, :] = keypoints[:, coco_order, :] |
| 26 | |
| 27 | keypoints_h36m[:, 9, :] -= (keypoints_h36m[:, 9, :] - np.mean(keypoints[:, 5:7, :], axis=1, dtype=np.float32)) / 4 |
| 28 | keypoints_h36m[:, 7, 0] += 2*(keypoints_h36m[:, 7, 0] - np.mean(keypoints_h36m[:, [0, 8], 0], axis=1, dtype=np.float32)) |
| 29 | keypoints_h36m[:, 8, 1] -= (np.mean(keypoints[:, 1:3, 1], axis=1, dtype=np.float32) - keypoints[:, 0, 1])*2/3 |
| 30 | |
| 31 | # half body: the joint of ankle and knee equal to hip |
| 32 | # keypoints_h36m[:, [2, 3]] = keypoints_h36m[:, [1, 1]] |
| 33 | # keypoints_h36m[:, [5, 6]] = keypoints_h36m[:, [4, 4]] |
| 34 | |
| 35 | valid_frames = np.where(np.sum(keypoints_h36m.reshape(-1, 34), axis=1) != 0)[0] |
| 36 | |
| 37 | return keypoints_h36m, valid_frames |
| 38 | |
| 39 | |
| 40 | def h36m_coco_format(keypoints, scores): |