-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathxml2txt.py
76 lines (54 loc) · 1.91 KB
/
xml2txt.py
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import xml.etree.ElementTree as elemTree
import os
import pprint
from absl import app, flags, logging
from absl.flags import FLAGS
"""
python xml2txt.py \
--gt_path ./resources/gt/T-ara_gt.xml \
--gt_file_path ./resources/gt/T-ara_gt.txt
python xml2txt.py \
--gt_path ./resources/gt/GirlsAloud_gt.xml \
--gt_file_path ./resources/gt/GirlsAloud_gt.txt
python xml2txt.py \
--gt_path ./resources/gt/Darling_gt.xml \
--gt_file_path ./resources/gt/Darling_gt.txt
python xml2txt.py \
--gt_path ./resources/gt/Westlife_gt.xml \
--gt_file_path ./resources/gt/Westlife_gt.txt
python xml2txt.py \
--gt_path ./resources/gt/BrunoMars_gt.xml \
--gt_file_path ./resources/gt/BrunoMars_gt.txt
python xml2txt.py \
--gt_path ./resources/gt/HelloBubble_gt.xml \
--gt_file_path ./resources/gt/HelloBubble_gt.txt
python xml2txt.py \
--gt_path ./resources/gt/Apink_gt.xml \
--gt_file_path ./resources/gt/Apink_gt.txt
"""
flags.DEFINE_string('gt_path', './resources/gt/T-ara_gt.xml', 'path to gt')
flags.DEFINE_string('gt_file_path', './resources/gt/T-ara_gt.txt', 'path to save converted file')
def main(args):
tree = elemTree.parse(FLAGS.gt_path)
root=tree.getroot()
print(root.tag, root.attrib)
print(root.find("Trajectory"))
frame_list = []
for traj in root:
for f in traj:
a = f.attrib
a["frame_no"] = str(int(a["frame_no"])-1)
a["id"] = traj.attrib["obj_id"]
frame_list.append(a)
frame_list = sorted(frame_list, key= lambda x: (int(x["frame_no"]), int(x["id"])))
# pprint.pprint(frame_list)
f = open(FLAGS.gt_file_path, 'w')
for a in frame_list:
f.write(a["frame_no"] + " " + a["id"] + " " + a["x"] + " " + a["y"] + " " + a["width"] + " " + a["height"] + "\n")
# 파일 닫기
f.close()
if __name__ == '__main__':
try:
app.run(main)
except SystemExit:
pass