-
Notifications
You must be signed in to change notification settings - Fork 1
/
sensor_defects_xml2mc.py
51 lines (42 loc) · 1.51 KB
/
sensor_defects_xml2mc.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
#!/bin/env python3
import sys
import os
import xml.etree.ElementTree as ET
def parseXml(fn):
""" Parsing Falcon 4 defects xml file to txt in Motioncor format."""
defects = [] # x y w h
tree = ET.parse(fn)
root = tree.getroot()
for item in root:
if item.tag == "point":
point = item.text.split(",")
defects.append((int(point[0]), int(point[1]), 1, 1))
elif item.tag == "area":
area = item.text.split(",")
defects.append((int(area[0]),
int(area[1]),
int(area[2])-int(area[0])+1,
int(area[3])-int(area[1])+1))
elif item.tag == "col":
area = item.text.split("-")
defects.append((int(area[0]), 0,
int(area[1])-int(area[0])+1,
4096))
elif item.tag == "row":
area = item.text.split("-")
defects.append((0, int(area[0]),
4096,
int(area[1])-int(area[0])+1))
if defects:
with open("defects.txt", "w") as f:
for d in defects:
print(d)
f.write(" ".join(str(i) for i in d) + "\n")
print("Saved to defects.txt")
def main():
if len(sys.argv) == 2:
parseXml(sys.argv[1])
else:
raise ValueError(f"Unrecognized input, please use: {os.path.basename(sys.argv[0])} SensorDefects.xml")
if __name__ == "__main__":
main()