示例:
<annotation verified="no">
<folder>IDcard—1000</folder>
<filename>1_0</filename>
<path>C:/Users/data/IDcard—1000/1_0.jpg</path>
<source>
<database>Unknown</database>
</source>
<size>
<width>1732</width>
<height>2309</height>
<depth>3</depth>
</size>
<segmented>0</segmented>
<mode>0</mode>
<object>
<name>王哲婷</name>
<pose>Unspecified</pose>
<truncated>0</truncated>
<difficult>0</difficult>
<bndbox>
<xmin>357</xmin>
<ymin>706</ymin>
<xmax>597</xmax>
<ymax>803</ymax>
</bndbox>
</object>
....
<object>
<name>姓名</name>
<pose>Unspecified</pose>
<truncated>0</truncated>
<difficult>0</difficult>
<bndbox>
<xmin>159</xmin>
<ymin>736</ymin>
<xmax>314</xmax>
<ymax>813</ymax>
</bndbox>
</object>
</annotation>
得到每一个object,解析其name和bndbox的值
#导入
import xml.etree.ElementTree as ET
#待解析的文件路径
xml_path = ''
#建立tree
tree = ET.parse(xml_path)
#得到根节点
root = tree.getroot()
#按照‘object’检索出所有的object, 返回为一个列表
objs = root.findall("object")
#获取每一个object的name和bndbox
for obj in objs:
name = obj[0].text
bndbox = obj[4]
xmin, ymin, xmax, ymax = [x.text for x in bndbox]