1200字范文,内容丰富有趣,写作的好帮手!
1200字范文 > labelme标注的json文件转化成ICDAR格式

labelme标注的json文件转化成ICDAR格式

时间:2020-10-24 16:02:39

相关推荐

labelme标注的json文件转化成ICDAR格式

在转换之前一定要备份备份备份备份备份!!!!!!!!!!!!!!!!!!

# -*- coding: utf-8 -*-import osimport jsondef jsonTotxt(jsonfile):filename = os.path.split(jsonfile)[1].split('.')[0]savefile = os.path.join("F:/nongzi/demo", filename + '.txt')#转换的路径# read json#setting = []with open(jsonfile, 'r') as f:b = f.read()#b = b.encode("utf-8-sig")data = json.loads(b)#print(data)with open(savefile, "a", encoding='utf-8') as f:for coordict in data['shapes']:coordlist = coordict['points']for point in coordlist:point[0] = int(point[0])point[1] = int(point[1])f.write(str(point).replace('[', '').replace(', ', ',').replace(']', '') + ',')f.write('###' + '\n')if __name__ == '__main__':path = r"F:\nongzi\demo"#json所在路径for root, dirs, files in os.walk(path, topdown=False):for file in files:portion = os.path.splitext(file)# print(portion)if portion[1] == ".json":jsonTotxt(os.path.join(path, file))

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。