-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathgenText.py
54 lines (49 loc) · 1.6 KB
/
genText.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
import os
'''
generate the txt file for train/test in our framework
'''
############ Utility functions ############
def get_images(img_path):
'''
find image files in data path
:return: list of files found
'''
img_path = os.path.abspath(img_path)
files = []
exts = ['jpg', 'png', 'jpeg', 'JPG', 'PNG']
for parent, dirnames, filenames in os.walk(img_path):
for filename in filenames:
for ext in exts:
if filename.endswith(ext):
files.append(os.path.join(parent, filename))
break
print('Find {} images'.format(len(files)))
return sorted(files)
def get_txts(txt_path):
'''
find gt files in data path
:return: list of files found
'''
txt_path = os.path.abspath(txt_path)
files = []
exts = ['txt']
for parent, dirnames, filenames in os.walk(txt_path):
for filename in filenames:
for ext in exts:
if filename.endswith(ext):
files.append(os.path.join(parent, filename))
break
print('Find {} txts'.format(len(files)))
return sorted(files)
if __name__ == '__main__':
img_path = '/home1/surfzjy/data/ICDAR-13and15/train_data'
files = get_images(img_path)
txt_path = '/home1/surfzjy/data/ICDAR-13and15/train_data'
txts = get_txts(txt_path)
n = len(files)
assert len(files) == len(txts)
with open('dataset_ic13and15_train.txt', 'w') as f:
for i in range(n):
line = files[i] + '\t' + txts[i] + '\n'
f.write(line)
print('dataset generated ^_^ ')