def _parse_annotation_xml(filepath):
tree = et.parse(filepath)
data = tree.getroot()[1] # <data>
for sf in data: # <sourcefile> ... find first non-empty sourcefile node
if len(list(sf)) != 0:
break
file = sf[0] # <file>
objs = sf[1:] # <object> ...
num_objs = len(objs)
num_frames = int(file.find("./*[@name='NUMFRAMES']/*[@value]").attrib['value'])
parsed_bbx = np.zeros([num_frames, num_objs, 4])
for i, obj in enumerate(objs): # iterate <object> nodes
loc = obj.find("./*[@name='Location']")
for bbx in loc:
span = re.findall(r'\d+', bbx.attrib['framespan'])
beg, end = int(span[0]), int(span[1])
h = int(bbx.attrib['height'])
w = int(bbx.attrib['width'])
x = int(bbx.attrib['x'])
y = int(bbx.attrib['y'])
parsed_bbx[beg-1:end, i] = [h, w, x, y]
return parsed_bbx
generate_tfrecord.py 文件源码
python
阅读 21
收藏 0
点赞 0
评论 0
评论列表
文章目录