-
Notifications
You must be signed in to change notification settings - Fork 0
/
get_gt_txt.py
25 lines (20 loc) · 910 Bytes
/
get_gt_txt.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# mAP所需文件计算代码
import os
import xml.etree.ElementTree as ET
image_ids = open('VOCdevkit/VOC/ImageSets/Main/list.txt').read().strip().split()
if not os.path.exists("input"):
os.makedirs("./input")
if not os.path.exists("input/ground-truth"):
os.makedirs("./input/ground-truth")
for image_id in image_ids:
with open("./input/ground-truth/" + image_id + ".txt", "a") as new_f:
root = ET.parse("VOCdevkit/VOC/Annotations/" + image_id + ".xml").getroot()
for obj in root.findall('object'):
obj_name = obj.find('name').text
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!")