-
Notifications
You must be signed in to change notification settings - Fork 3
/
gen_detect_data.py
34 lines (30 loc) · 1.13 KB
/
gen_detect_data.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
import os
import glob
import codecs
def start(dataroot):
label_path= os.path.join(dataroot , "label_gen")
detection_label_path = os.path.join(dataroot , "detection_label")
if not os.path.exists(detection_label_path):
os.mkdir(detection_label_path)
files=[]
for ext in ['txt']:
files.extend(glob.glob(
os.path.join(label_path, '*.{}'.format(ext))))
for fn in files:
basename = os.path.basename(fn)
fw = open(os.path.join(detection_label_path,basename),'w', encoding='utf-8')
with open(fn, 'r',encoding="utf-8") as f:
for idx, line in enumerate(f.readlines()):
line = line.rstrip()
if line.startswith("[[") or line.startswith(" ["):
continue
lx, ly, rx, ry = line.split(" ")[:4]
ch = line[line.find("\""):][1:-1]
if idx != 0:
fw.write("\n")
fw.write((",").join([lx, ly, rx, ly, rx, ry, lx, ry]))
fw.write("," + ch)
fw.close()
if __name__=='__main__':
data_root = "data/dataset/wot/"
start(data_root)