-
Notifications
You must be signed in to change notification settings - Fork 72
Expand file tree
/
Copy pathparse.py
More file actions
46 lines (32 loc) · 1.13 KB
/
parse.py
File metadata and controls
46 lines (32 loc) · 1.13 KB
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import os
import glob
import pandas as pd
import xml.etree.ElementTree as ET
from lxml import etree
def xml_to_csv(path):
xml_list = []
for xml_file in glob.glob(path + '/*.xml'):
tree = ET.parse(xml_file)
doc = etree.parse(xml_file)
count = doc.xpath("count(//object)")
root = tree.getroot()
with open(str(xml_file)[0:-4]+".csv","w+") as f:
f.write(str(int(count)))
for member in root.findall('object'):
value = (
member[4][0].text,
member[4][1].text,
member[4][2].text,
member[4][3].text
)
coord = " ".join(value)
with open(str(xml_file)[0:-4]+".csv","a") as f:
f.write("\n")
f.write(coord)
#xml_list.append(value)
def main():
image_path ="annotations"
xml_df = xml_to_csv(image_path)
#xml_df.to_csv('1.csv', index=None)
print('Successfully converted xml to csv.')
main()