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/')
因篇幅问题不能全部显示,请点此查看更多更全内容
Copyright © 2019- sarr.cn 版权所有 赣ICP备2024042794号-1
违法及侵权请联系:TEL:199 1889 7713 E-MAIL:2724546146@qq.com
本站由北京市万商天勤律师事务所王兴未律师提供法律服务