Advertisement
Guest User

Untitled

a guest
Feb 25th, 2018
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.87 KB | None | 0 0
  1. def xml_to_csv(path):
  2. xml_list = []
  3. for xml_file in glob.glob(path + '/*.xml'):
  4. tree = ET.parse(xml_file)
  5. root = tree.getroot()
  6. for member in root.findall('object'):
  7. bndbox = member.find('bndbox')
  8. value = (root.find('filename').text,
  9. int(root.find('size')[0].text),
  10. int(root.find('size')[1].text),
  11. member.find('name').text,
  12. int(bndbox.find('xmin').text),
  13. int(bndbox.find('ymin').text),
  14. int(bndbox.find('xmax').text),
  15. int(bndbox.find('ymax').text)
  16. )
  17. xml_list.append(value)
  18. column_name = ['filename', 'width', 'height', 'class', 'xmin', 'ymin', 'xmax', 'ymax']
  19. xml_df = pd.DataFrame(xml_list, columns=column_name)
  20. return xml_df
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement