(data_to_json, none_idx, dst_shape, bone_ratio_list, delta_ground_x, delta_ground_y, rescaled_src_ground_x, body_flag, scale_min)
| 493 | |
| 494 | |
| 495 | def write_to_poses(data_to_json, none_idx, dst_shape, bone_ratio_list, delta_ground_x, delta_ground_y, rescaled_src_ground_x, body_flag, scale_min): |
| 496 | outputs = [] |
| 497 | length = len(data_to_json) |
| 498 | for id in tqdm(range(length)): |
| 499 | src_height, src_width = data_to_json[id]["height"], data_to_json[id]["width"] |
| 500 | width, height = dst_shape |
| 501 | keypoints = data_to_json[id]["keypoints_body"] |
| 502 | for idx in range(len(keypoints)): |
| 503 | if idx in none_idx: |
| 504 | keypoints[idx] = None |
| 505 | new_keypoints = keypoints.copy() |
| 506 | |
| 507 | # get hand keypoints |
| 508 | keypoints_hand = {"left": data_to_json[id]["keypoints_left_hand"], "right": data_to_json[id]["keypoints_right_hand"]} |
| 509 | # Normalize hand coordinates to 0-1 range |
| 510 | for hand_idx in range(len(data_to_json[id]["keypoints_left_hand"])): |
| 511 | data_to_json[id]["keypoints_left_hand"][hand_idx][0] = data_to_json[id]["keypoints_left_hand"][hand_idx][0] / src_width |
| 512 | data_to_json[id]["keypoints_left_hand"][hand_idx][1] = data_to_json[id]["keypoints_left_hand"][hand_idx][1] / src_height |
| 513 | |
| 514 | for hand_idx in range(len(data_to_json[id]["keypoints_right_hand"])): |
| 515 | data_to_json[id]["keypoints_right_hand"][hand_idx][0] = data_to_json[id]["keypoints_right_hand"][hand_idx][0] / src_width |
| 516 | data_to_json[id]["keypoints_right_hand"][hand_idx][1] = data_to_json[id]["keypoints_right_hand"][hand_idx][1] / src_height |
| 517 | |
| 518 | frame_info = get_scaled_pose( |
| 519 | (height, width), (src_height, src_width), new_keypoints, keypoints_hand, bone_ratio_list, delta_ground_x, delta_ground_y, rescaled_src_ground_x, body_flag, id, scale_min |
| 520 | ) |
| 521 | outputs.append(frame_info) |
| 522 | |
| 523 | return outputs |
| 524 | |
| 525 | |
| 526 | def calculate_scale_ratio(skeleton, skeleton_edit, scale_ratio_flag): |
no test coverage detected