别问,就是写着玩
from pypinyin import lazy_pinyin
for image_id in image_ids:
with open("./input/ground-truth/"+image_id+".txt", "a", encoding='utf8') as new_f:
root = ET.parse("/home/yons/data/huawei/shenzhen/trainval/VOC2007/Annotations/"+image_id+".xml").getroot()
for obj in root.findall('object'):
obj_name = obj.find('name').text
obj_name = '_'.join(lazy_pinyin(obj_name))
bndbox = obj.find('bndbox')
left = bndbox.find('xmin').text
top = bndbox.find('ymin').text
right = bndbox.find('xmax').text
bottom = bndbox.find('ymax').text
new_f.write("%s %s %s %s %s\n" % (obj_name, left, top, right, bottom))
print("Conversion completed!")