-1

嘿,所有人都找不到一个好的答案,但我做了一个对我有用的小方法。希望如果其他人正在寻找它会有所帮助。它有点hacky,但会服务。

4

1 回答 1

0
```
import pandas as pd
import xml.etree.ElementTree as ET


test_xml = '/Users/cole/PycharmProjects/Birds/VisualizeConvsTest/Robin.xml'

tree = ET.parse(test_xml)
root = tree.getroot()

labelimg_params = {}
#takes an empty dict and adds in the params as we recursively go through the xml file
def find_children(root, params):

    children = root.getchildren()
    for child in children:
        if child.getchildren():
            find_children(child, params)
        params[child.tag] = child.text
        #print(child.tag, child.text)
    return labelimg_params

xml_dict = find_children(root, labelimg_params)
df = pd.DataFrame([xml_dict])
print(df.columns.to_list())
bbox = df[['xmin', 'ymin', 'xmax', 'ymax']]
print(bbox)
```

['文件夹','文件名','路径','数据库','源','宽度','高度','深度','大小','分段','名称','姿势','截断','困难','xmin','ymin','xmax','ymax','bndbox','object']

xmin ymin xmax ymax

0 87 104 501 375

于 2022-01-14T10:32:40.377 回答