Commit 234ad1682e0a5e3a3c7c489cabaceceefc7cf809
1 parent
47a51f0a
Simple script to convert FDDB to xml
Showing
1 changed file
with
54 additions
and
0 deletions
data/FDDB/fddbToSigset.py
0 → 100644
| 1 | +# Simple script to convert files from the FDDB format into sigsets | |
| 2 | +# Author: Brendan Klare | |
| 3 | + | |
| 4 | +import os | |
| 5 | +import sys | |
| 6 | +from xml.dom.minidom import Document | |
| 7 | + | |
| 8 | +if len(sys.argv) < 3: | |
| 9 | + print 'Usage: fddbtoSigset.py fddbFileIn xmlSigsetFileOut' | |
| 10 | + sys.exit(-1) | |
| 11 | + | |
| 12 | +inFileName = sys.argv[1] | |
| 13 | +outFileName = sys.argv[2] | |
| 14 | +assert(os.path.exists(inFileName)) | |
| 15 | + | |
| 16 | +ini = open(inFileName) | |
| 17 | +lines = ini.readlines() | |
| 18 | +ini.close() | |
| 19 | + | |
| 20 | +xmlDoc = Document() | |
| 21 | +xmlRoot = xmlDoc.createElement('biometric-signature-set') | |
| 22 | +i = 0 | |
| 23 | +cnt = 0 | |
| 24 | +while True: | |
| 25 | + if not i < len(lines): | |
| 26 | + break | |
| 27 | + cnt += 1 | |
| 28 | + line = lines[i] | |
| 29 | + xmlImg = xmlDoc.createElement('biometric-signature') | |
| 30 | + xmlImg.setAttribute('name','img%05d' % cnt) | |
| 31 | + xmlPres = xmlDoc.createElement('presentation') | |
| 32 | + xmlPres.setAttribute('file-name',line[:-1]) | |
| 33 | + xmlPres.setAttribute('Label','pos') | |
| 34 | + | |
| 35 | + cnt = int(lines[i+1][:-1]) | |
| 36 | + for j in range(cnt): | |
| 37 | + node = xmlDoc.createElement('data:bbox') | |
| 38 | + s = lines[i+2+j][:-1].split() | |
| 39 | + radius = float(s[1]) | |
| 40 | + x = float(s[3]) | |
| 41 | + y = float(s[4]) | |
| 42 | + node.setAttribute('x',str(x - radius)) | |
| 43 | + node.setAttribute('y',str(y - radius)) | |
| 44 | + node.setAttribute('width',str(radius * 2.0)) | |
| 45 | + node.setAttribute('height',str(radius * 2.0)) | |
| 46 | + xmlPres.appendChild(node) | |
| 47 | + xmlImg.appendChild(xmlPres) | |
| 48 | + xmlRoot.appendChild(xmlImg) | |
| 49 | + i += (2 + cnt) | |
| 50 | + | |
| 51 | +out = open(outFileName,'w') | |
| 52 | +print >> out, xmlRoot.toprettyxml() | |
| 53 | +out.close() | |
| 54 | + | ... | ... |