|
| 1 | +''' |
| 2 | +(By default, this script will be automatically invoked by download_fddb.sh) |
| 3 | +
|
| 4 | +Manually invoke this script to generate image list and annotation files with |
| 5 | +absolute paths. |
| 6 | +
|
| 7 | +Please make sure this script stays aside with a folder fddb which contains |
| 8 | +sub-folders: 2002, 2003, FDDB-folds. |
| 9 | +
|
| 10 | +Invoke this script again after you move the directory of images. |
| 11 | +
|
| 12 | +''' |
| 13 | +import os |
| 14 | + |
| 15 | + |
| 16 | +assert os.path.exists("fddb/2002"), "fddb iamge folder 'fddb/2002' not found" |
| 17 | +assert os.path.exists("fddb/2003"), "fddb iamge folder 'fddb/2003' not found" |
| 18 | +assert os.path.exists("fddb/FDDB-folds"), "fddb annotation folder 'fddb/FDDB-folds' not found" |
| 19 | + |
| 20 | +os.chdir('fddb') |
| 21 | +prefix = os.getcwd() |
| 22 | +suffix = ".jpg" |
| 23 | +x=os.popen("pwd | sed 's/ /\\ /g'").read().strip() |
| 24 | +img_list_files = os.popen("find '{}/FDDB-folds' -name '*[0-9].txt'".format(x)).read().split('\n') |
| 25 | +anot_list_files = os.popen("find '{}/FDDB-folds' -name '*List.txt'".format(x)).read().split('\n') |
| 26 | + |
| 27 | + |
| 28 | +s = "" |
| 29 | +for p in img_list_files: |
| 30 | + if p == '' : |
| 31 | + continue |
| 32 | + with open(p,'r') as f: |
| 33 | + lines = f.readlines() |
| 34 | + lines = [os.path.join(prefix, l.replace('\n','')+suffix) for l in lines] |
| 35 | + s += "\n".join(lines)+'\n' |
| 36 | + |
| 37 | +with open("./MergedImagePath.txt",'w') as f: |
| 38 | + f.write(s) |
| 39 | + |
| 40 | +s = "" |
| 41 | +for p in anot_list_files: |
| 42 | + if p == '' : |
| 43 | + continue |
| 44 | + with open(p,'r') as f: |
| 45 | + lines = f.readlines() |
| 46 | + |
| 47 | + lines = [l.replace('\n','') for l in lines] |
| 48 | + for i in range(len(lines)): |
| 49 | + l = lines[i] |
| 50 | + if(len(l.split("/")) == 5): |
| 51 | + lines[i] = os.path.join(prefix, l+suffix) |
| 52 | + s += '\n'.join(lines)+'\n' |
| 53 | + |
| 54 | +with open("./MergedAnnotations.txt",'w') as f: |
| 55 | + f.write(s) |
| 56 | + |
| 57 | +print "Merged image path wrote to: "+os.path.join(os.getcwd(),"MergedImagePath.txt") |
| 58 | +print "Merged annotations wrote to: "+os.path.join(os.getcwd(),"MergedAnnotations.txt") |
| 59 | + |
| 60 | + |
0 commit comments