diff --git a/openbr/plugins/slidingwindow.cpp b/openbr/plugins/slidingwindow.cpp index 17f39c4..d874250 100644 --- a/openbr/plugins/slidingwindow.cpp +++ b/openbr/plugins/slidingwindow.cpp @@ -78,7 +78,6 @@ private: stream >> windowHeight; } -protected: // Let IntegralSlidingWindowTransform access this void project(const Template &src, Template &dst) const { (void)src;(void)dst;qFatal("don't do that"); @@ -86,6 +85,13 @@ protected: // Let IntegralSlidingWindowTransform access this void project(const TemplateList &src, TemplateList &dst) const { + float scale = src.first().file.get("scale", 1); + projectHelp(src, dst, windowWidth, windowHeight, scale); + } + +protected: + void projectHelp(const TemplateList &src, TemplateList &dst, int windowWidth, int windowHeight, float scale = 1) const + { // no need to slide a window over ground truth data if (src.first().file.getBool("Train", false)) { dst = src; @@ -93,9 +99,8 @@ protected: // Let IntegralSlidingWindowTransform access this } foreach (const Template &t, src) { - float scale = t.file.get("scale", 1); - for (double y = 0; y + windowHeight < t.m().rows; y += stepSize) { - for (double x = 0; x + windowWidth < t.m().cols; x += stepSize) { + for (float y = 0; y + windowHeight < t.m().rows; y += windowHeight*stepFraction) { + for (float x = 0; x + windowWidth < t.m().cols; x += windowWidth*stepFraction) { Mat windowMat(t.m(), Rect(x, y, windowWidth, windowHeight)); Template detect; transform->project(Template(t.file, windowMat), detect); @@ -103,7 +108,7 @@ protected: // Let IntegralSlidingWindowTransform access this // the result will be the only value in the Mat float conf = detect.m().at(0); if (conf > threshold) { - detect.file.set("Detection", QRectF((float) x * scale, (float) y * scale, (float) windowWidth * scale, (float) windowHeight * scale)); + detect.file.set("Detection", QRectF(x*scale, y*scale, windowWidth*scale, windowHeight*scale)); detect.file.set("Confidence", conf); dst.append(detect); if (takeFirst) @@ -127,10 +132,10 @@ class IntegralSlidingWindowTransform : public SlidingWindowTransform { Q_OBJECT - void project(const Template &src, Template &dst) const + void project(const TemplateList &src, TemplateList &dst) const { // TODO: call SlidingWindowTransform::project on multiple scales - SlidingWindowTransform::project(src, dst); + SlidingWindowTransform::projectHelp(src, dst, 24, 24); } }; diff --git a/scripts/downloadDatasets.sh b/scripts/downloadDatasets.sh index 95f9a74..22fb149 100755 --- a/scripts/downloadDatasets.sh +++ b/scripts/downloadDatasets.sh @@ -102,3 +102,21 @@ if [ ! -d ../data/MEDS/img ]; then mv data/*/*.jpg ../data/MEDS/img rm -r data NIST_SD32_MEDS-II_face.zip fi + +#LFPW +if [ ! -d ../data/lfpw/trainset ]; then + echo "Downloading LFPW..." + if hash curl 2>/dev/null; then + curl -OL http://ibug.doc.ic.ac.uk/media/uploads/competitions/lfpw.zip + else + wget http://ibug.doc.ic.ac.uk/media/uploads/competitions/lfpw.zip + fi + + unzip lfpw.zip + mv lfpw ../data + cd ../data/lfpw + python ../../scripts/lfpwToSigset.py + cd ../../scripts + rm lfpw.zip +fi + diff --git a/scripts/lfpwToSigset.py b/scripts/lfpwToSigset.py new file mode 100644 index 0000000..39e6fe0 --- /dev/null +++ b/scripts/lfpwToSigset.py @@ -0,0 +1,43 @@ +#!/usr/bin/python + +# This scripts converts the LFPW .pts files into xml sigsets that can be readily +# used within openbr. + +from xml.dom.minidom import Document +import glob +import os + +for lfpwType in ['train','test']: + files = glob.glob('%sset/*.pts' % lfpwType) + files.sort() + cnt = 0 + + xmlDoc = Document() + xmlRoot = xmlDoc.createElement('biometric-signature-set') + for ptsFile in files: + cnt += 1 + ini = open(ptsFile) + lines = ini.readlines() + ini.close() + + pntStrList = [] + n = int(lines[1].split()[1]) + for i in range(3,3+n): + pntStrList.append('(%s)' % (','.join(lines[i].split()))) + pntStr = '[%s]' % ','.join(pntStrList) + + xmlSubj = xmlDoc.createElement('biometric-signature') + xmlSubj.setAttribute('name','subj_%05d' % cnt) + xmlPres = xmlDoc.createElement('presentation') + xmlPres.setAttribute('file-name','%sset/%s.png' % (lfpwType,os.path.splitext(ptsFile)[0])) + xmlPres.setAttribute('Points',pntStr) + xmlSubj.appendChild(xmlPres) + xmlRoot.appendChild(xmlSubj) + + if not os.path.exists('sigset'): + os.mkdir('sigset') + out = open('sigset/%s.xml' % lfpwType,'w') + print >> out, xmlRoot.toprettyxml() + out.close() + +