"""
从AplhaPose输出json文件中读取pose信息
"""
import json
import numpy as np
def load_json(filename):
    with open(filename, "r") as fr:
        data = json.load(fr)
    return data
def save_json(filename, data):
    with open(filename, "w", encoding="utf-8") as fw:
        json.dump(data, fw, ensure_ascii=False, indent=4)
data = load_json("/home/lwk/github_mine/AlphaPose/examples/res/alphapose-results.json")

results = dict()
for item in data:
    image_id = int(item["image_id"].split(".")[0])

    pose_2d = np.array(item["keypoints"]).reshape(17, 3).tolist()
    if image_id not in results:
        results[image_id] = []
    results[image_id].append(pose_2d)

save_json("1.json", results)
