-
Notifications
You must be signed in to change notification settings - Fork 0
/
Create_XML_file_for_random_bounding_box.py
52 lines (50 loc) · 1.52 KB
/
Create_XML_file_for_random_bounding_box.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
import os
import random
import lxml.etree as ET
import lxml.builder import E
somepath="./1/"
XMIN=1335
YMIN=449
XMAX=1376
YMAX=510
for (dirpath,dirnames,filenames) in walk(some_path):
for item in filenames:
xmin1=XMIN+random.randint(-10,10)
ymin1=YMIN+random.randint(-5,5)
xmax1=XMAX+random.randint(-10,10)
ymax1=YMAX+random.randint(-5,5)
p=dirpath+item
file=(
E.annotation(
E.folder("1"),
E,filename(item),
E.path(p),
E.source(
E.database("Unknown")
),
E.size(
E.width("1920"),
E.height("1090"),
E.depth("3")
)
E.segmented("0"),
E.object(
E.name("reference"),
E.pose("Unspecified"),
E.truncated("0"),
E.difficult("0"),
E.bnd_box(
E.xmin(str(xmin1)),
E.ymin(str(ymin1)),
E.xmax(str(xmax1)),
E.ymax(str(ymax1))
)
)
)
)
XML_data=ET.tostring(file)
XML_data=XML_data.decode("utf-8")
fname=dirpath+str(item.split(".")[0])+".xml"
print(fname)
f=open(fname,"w+")
f.write(str(XML_data))