人体关键点的coco格式转xml以及xml转coco

一. coco格式数据集

coco格式数据集是将信息以字典列表的形式存储在json文件中,读取和解析都比较方便,被广泛使用。在人体关键点中,coco存储的格式如下:


 ##1. 定义字典的名字和key,实例中person_keypoint 有3个key

	person_keypoint = {
   }
	person_keypoint['images'] = []
	person_keypoint['annotations'] = []
	person_keypoint['categories'] = [{
   "supercategory": "human",
                                  "skeleton": [[1, 2], [2, 3], [2, 4], [3, 5], [5, 7], [4, 6],[6, 8], [2, 9], [2, 10],
                                               [9, 11], [10, 12],[11, 13], [12, 14]],
                                  "id": 1,
                                  "keypoints": ["top_head", "neck", "left_shoulder", "right_shoulder", "left_elbow",
                                                "right_elbow", "left_wrist", "right_wrist", "left_hip", "right_hip",
                                                "left_knee", "right_knee", "left_ankle", "right_ankle"],
                                  "name": "human"}]

 ##2. 定义每一张图片标注信息的字典,然后用append放入'images'和'annotations'中

     img_info={
   }
     img_info['file_name']=filename
     img_info['height']=h
     img_info['width']=w
     img_info['id']=count
     ann_info={
   }
     ann_info['num_keypoints']=14
     ann_info['keypoints']=coco_points
     ann_info['area']=area
     ann_info['bbox']=box
     ann_info['image_id']=count
     ann_info['id']=count
     ann_info['category_id']=1
     person_keypoint['images'].append(img_info)
     person_keypoint['annotations'].append(ann_info)

##  3. 将person_keypoint保存到json文件中

    with open(r'task9.json', 'w', encoding='utf-8') as f:
        json.dump(person_keypoint, f)

二. 标题将json解析问xml代码

简单的coco的json文件如下,其中num_keypoints中存储了14个点,keypoints中三个为一个点641, 693, 1,第三个"1"是额外的信息,一般为概率或是实现/虚线。所以,读取coco的keypoints时要转换

{
   "images": [{
   "file_name": "pose_0426_task0_0000.jpg", "height": 1920, "width": 1080, "id": 1}, {
   "file_name": "pose_0426_task0_0001.jpg", "height": 1920, "width": 1080, "id": 2},……,
"annotations": [{
   "num_keypoints": 14, "keypoints": [641, 693, 1, 614, 803, 1, 634, 840, 0, 577, 831, 0, 625, 745, 0, 596, 745, 0, 641, 645, 0, 608, 667, 0, 644, 1099, 0, 625, 1089, 0, 627, 1309, 0, 609, 1286, 0, 608, 1491, 0, 547, 1544, 0], "area": 257985, "bbox": [496, 565, 245, 1053], "image_id": 1, "id": 1, "category_id": 1},
{
   "num_keypoints": 14, "keypoints": [689, 883, 1, 703, 980, 1, 652, 1015, 0, 750, 992, 0, 615, 1048, 0, 639, 1009, 0, 645, 961, 0, 546, 1037, 0, 649, 1198, 0, 733, 1208, 0, 644, 1361, 0, 736, 1376, 0, 646, 1529, 0, 735, 1550, 0], "area": 241653, "bbox": [501, 872, 327, 739], "image_id": 2, "id": 2, "category_id": 1},……,
"categories": [{
   "supercategory": "human", "skeleton": [[1, 2], [2, 3], [2, 4], [3, 5], [5, 7], [4, 6], [6, 8], [2, 9], [2, 10], [9, 11], [10, 12], [11, 13], [12, 14]], "id": 1, "keypoints"</
  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值