matterport/MaskRCNN labelme转coco文件

import json,os
import numpy as np

def labelme2coco(path):
# path='./json'

    files=[]
    for file in os.listdir(path):
        if file[-5:]=='.json':
            files.append(file)
        # break
    print(json.load(open(path+files[0])))

    via_region_data={}

    for file in files:
        one_json=json.load(open(path+file))

        one_image={}
        one_image['filename']=file.split('.')[0]+'.jpg'
        shape=one_json['shapes']
        regions={}
        for i in range(len(shape)):
            points=np.array(shape[i]['points'])
            all_points_x=points[:,0].tolist()
            all_points_y=points[:,1].tolist()

            regions[str(i)]={}
            regions[str(i)]['region_attributes']={}
            regions[str(i)]['shape_attributes']={}

            regions[str(i)]['shape_attributes']['all_points_x'] = all_points_x
            regions[str(i)]['shape_attributes']['all_points_y'] = all_points_y
            regions[str(i)]['shape_attributes']['name'] = shape[i]['label']
        one_image['regions']=regions
        one_image['size']=0

        via_region_data[file]=one_image

    with open('via_region_data.json','w') as f:
        json.dump(via_region_data,f,sort_keys=False,ensure_ascii=True)

if __name__ == '__main__':
    labelme2coco('./json/')
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值