-
Notifications
You must be signed in to change notification settings - Fork 0
/
gen_absolute_path.py
60 lines (44 loc) · 1.77 KB
/
gen_absolute_path.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
'''
(By default, this script will be automatically invoked by download_fddb.sh)
Manually invoke this script to generate image list and annotation files with
absolute paths.
Please make sure this script stays aside with a folder fddb which contains
sub-folders: 2002, 2003, FDDB-folds.
Invoke this script again after you move the directory of images.
'''
import os
assert os.path.exists("fddb/2002"), "fddb iamge folder 'fddb/2002' not found"
assert os.path.exists("fddb/2003"), "fddb iamge folder 'fddb/2003' not found"
assert os.path.exists("fddb/FDDB-folds"), "fddb annotation folder 'fddb/FDDB-folds' not found"
os.chdir('fddb')
prefix = os.getcwd()
suffix = ".jpg"
x=os.popen("pwd | sed 's/ /\\ /g'").read().strip()
img_list_files = os.popen("find '{}/FDDB-folds' -name '*[0-9].txt'".format(x)).read().split('\n')
anot_list_files = os.popen("find '{}/FDDB-folds' -name '*List.txt'".format(x)).read().split('\n')
s = ""
for p in img_list_files:
if p == '' :
continue
with open(p,'r') as f:
lines = f.readlines()
lines = [os.path.join(prefix, l.replace('\n','')+suffix) for l in lines]
s += "\n".join(lines)+'\n'
with open("./MergedImagePath.txt",'w') as f:
f.write(s)
s = ""
for p in anot_list_files:
if p == '' :
continue
with open(p,'r') as f:
lines = f.readlines()
lines = [l.replace('\n','') for l in lines]
for i in range(len(lines)):
l = lines[i]
if(len(l.split("/")) == 5):
lines[i] = os.path.join(prefix, l+suffix)
s += '\n'.join(lines)+'\n'
with open("./MergedAnnotations.txt",'w') as f:
f.write(s)
print "Merged image path wrote to: "+os.path.join(os.getcwd(),"MergedImagePath.txt")
print "Merged annotations wrote to: "+os.path.join(os.getcwd(),"MergedAnnotations.txt")