Commit 4db5b304a5edc9da9447a4e91c43368fa830e234
Merge MORE sliding window conflicts
Conflicts: openbr/plugins/slidingwindow.cpp
Showing
3 changed files
with
73 additions
and
7 deletions
openbr/plugins/slidingwindow.cpp
| @@ -78,7 +78,6 @@ private: | @@ -78,7 +78,6 @@ private: | ||
| 78 | stream >> windowHeight; | 78 | stream >> windowHeight; |
| 79 | } | 79 | } |
| 80 | 80 | ||
| 81 | -protected: // Let IntegralSlidingWindowTransform access this | ||
| 82 | void project(const Template &src, Template &dst) const | 81 | void project(const Template &src, Template &dst) const |
| 83 | { | 82 | { |
| 84 | (void)src;(void)dst;qFatal("don't do that"); | 83 | (void)src;(void)dst;qFatal("don't do that"); |
| @@ -86,6 +85,13 @@ protected: // Let IntegralSlidingWindowTransform access this | @@ -86,6 +85,13 @@ protected: // Let IntegralSlidingWindowTransform access this | ||
| 86 | 85 | ||
| 87 | void project(const TemplateList &src, TemplateList &dst) const | 86 | void project(const TemplateList &src, TemplateList &dst) const |
| 88 | { | 87 | { |
| 88 | + float scale = src.first().file.get<float>("scale", 1); | ||
| 89 | + projectHelp(src, dst, windowWidth, windowHeight, scale); | ||
| 90 | + } | ||
| 91 | + | ||
| 92 | +protected: | ||
| 93 | + void projectHelp(const TemplateList &src, TemplateList &dst, int windowWidth, int windowHeight, float scale = 1) const | ||
| 94 | + { | ||
| 89 | // no need to slide a window over ground truth data | 95 | // no need to slide a window over ground truth data |
| 90 | if (src.first().file.getBool("Train", false)) { | 96 | if (src.first().file.getBool("Train", false)) { |
| 91 | dst = src; | 97 | dst = src; |
| @@ -93,9 +99,8 @@ protected: // Let IntegralSlidingWindowTransform access this | @@ -93,9 +99,8 @@ protected: // Let IntegralSlidingWindowTransform access this | ||
| 93 | } | 99 | } |
| 94 | 100 | ||
| 95 | foreach (const Template &t, src) { | 101 | foreach (const Template &t, src) { |
| 96 | - float scale = t.file.get<float>("scale", 1); | ||
| 97 | - for (double y = 0; y + windowHeight < t.m().rows; y += stepSize) { | ||
| 98 | - for (double x = 0; x + windowWidth < t.m().cols; x += stepSize) { | 102 | + for (float y = 0; y + windowHeight < t.m().rows; y += windowHeight*stepFraction) { |
| 103 | + for (float x = 0; x + windowWidth < t.m().cols; x += windowWidth*stepFraction) { | ||
| 99 | Mat windowMat(t.m(), Rect(x, y, windowWidth, windowHeight)); | 104 | Mat windowMat(t.m(), Rect(x, y, windowWidth, windowHeight)); |
| 100 | Template detect; | 105 | Template detect; |
| 101 | transform->project(Template(t.file, windowMat), detect); | 106 | transform->project(Template(t.file, windowMat), detect); |
| @@ -103,7 +108,7 @@ protected: // Let IntegralSlidingWindowTransform access this | @@ -103,7 +108,7 @@ protected: // Let IntegralSlidingWindowTransform access this | ||
| 103 | // the result will be the only value in the Mat | 108 | // the result will be the only value in the Mat |
| 104 | float conf = detect.m().at<float>(0); | 109 | float conf = detect.m().at<float>(0); |
| 105 | if (conf > threshold) { | 110 | if (conf > threshold) { |
| 106 | - detect.file.set("Detection", QRectF((float) x * scale, (float) y * scale, (float) windowWidth * scale, (float) windowHeight * scale)); | 111 | + detect.file.set("Detection", QRectF(x*scale, y*scale, windowWidth*scale, windowHeight*scale)); |
| 107 | detect.file.set("Confidence", conf); | 112 | detect.file.set("Confidence", conf); |
| 108 | dst.append(detect); | 113 | dst.append(detect); |
| 109 | if (takeFirst) | 114 | if (takeFirst) |
| @@ -127,10 +132,10 @@ class IntegralSlidingWindowTransform : public SlidingWindowTransform | @@ -127,10 +132,10 @@ class IntegralSlidingWindowTransform : public SlidingWindowTransform | ||
| 127 | { | 132 | { |
| 128 | Q_OBJECT | 133 | Q_OBJECT |
| 129 | 134 | ||
| 130 | - void project(const Template &src, Template &dst) const | 135 | + void project(const TemplateList &src, TemplateList &dst) const |
| 131 | { | 136 | { |
| 132 | // TODO: call SlidingWindowTransform::project on multiple scales | 137 | // TODO: call SlidingWindowTransform::project on multiple scales |
| 133 | - SlidingWindowTransform::project(src, dst); | 138 | + SlidingWindowTransform::projectHelp(src, dst, 24, 24); |
| 134 | } | 139 | } |
| 135 | }; | 140 | }; |
| 136 | 141 |
scripts/downloadDatasets.sh
| @@ -102,3 +102,21 @@ if [ ! -d ../data/MEDS/img ]; then | @@ -102,3 +102,21 @@ if [ ! -d ../data/MEDS/img ]; then | ||
| 102 | mv data/*/*.jpg ../data/MEDS/img | 102 | mv data/*/*.jpg ../data/MEDS/img |
| 103 | rm -r data NIST_SD32_MEDS-II_face.zip | 103 | rm -r data NIST_SD32_MEDS-II_face.zip |
| 104 | fi | 104 | fi |
| 105 | + | ||
| 106 | +#LFPW | ||
| 107 | +if [ ! -d ../data/lfpw/trainset ]; then | ||
| 108 | + echo "Downloading LFPW..." | ||
| 109 | + if hash curl 2>/dev/null; then | ||
| 110 | + curl -OL http://ibug.doc.ic.ac.uk/media/uploads/competitions/lfpw.zip | ||
| 111 | + else | ||
| 112 | + wget http://ibug.doc.ic.ac.uk/media/uploads/competitions/lfpw.zip | ||
| 113 | + fi | ||
| 114 | + | ||
| 115 | + unzip lfpw.zip | ||
| 116 | + mv lfpw ../data | ||
| 117 | + cd ../data/lfpw | ||
| 118 | + python ../../scripts/lfpwToSigset.py | ||
| 119 | + cd ../../scripts | ||
| 120 | + rm lfpw.zip | ||
| 121 | +fi | ||
| 122 | + |
scripts/lfpwToSigset.py
0 → 100644
| 1 | +#!/usr/bin/python | ||
| 2 | + | ||
| 3 | +# This scripts converts the LFPW .pts files into xml sigsets that can be readily | ||
| 4 | +# used within openbr. | ||
| 5 | + | ||
| 6 | +from xml.dom.minidom import Document | ||
| 7 | +import glob | ||
| 8 | +import os | ||
| 9 | + | ||
| 10 | +for lfpwType in ['train','test']: | ||
| 11 | + files = glob.glob('%sset/*.pts' % lfpwType) | ||
| 12 | + files.sort() | ||
| 13 | + cnt = 0 | ||
| 14 | + | ||
| 15 | + xmlDoc = Document() | ||
| 16 | + xmlRoot = xmlDoc.createElement('biometric-signature-set') | ||
| 17 | + for ptsFile in files: | ||
| 18 | + cnt += 1 | ||
| 19 | + ini = open(ptsFile) | ||
| 20 | + lines = ini.readlines() | ||
| 21 | + ini.close() | ||
| 22 | + | ||
| 23 | + pntStrList = [] | ||
| 24 | + n = int(lines[1].split()[1]) | ||
| 25 | + for i in range(3,3+n): | ||
| 26 | + pntStrList.append('(%s)' % (','.join(lines[i].split()))) | ||
| 27 | + pntStr = '[%s]' % ','.join(pntStrList) | ||
| 28 | + | ||
| 29 | + xmlSubj = xmlDoc.createElement('biometric-signature') | ||
| 30 | + xmlSubj.setAttribute('name','subj_%05d' % cnt) | ||
| 31 | + xmlPres = xmlDoc.createElement('presentation') | ||
| 32 | + xmlPres.setAttribute('file-name','%sset/%s.png' % (lfpwType,os.path.splitext(ptsFile)[0])) | ||
| 33 | + xmlPres.setAttribute('Points',pntStr) | ||
| 34 | + xmlSubj.appendChild(xmlPres) | ||
| 35 | + xmlRoot.appendChild(xmlSubj) | ||
| 36 | + | ||
| 37 | + if not os.path.exists('sigset'): | ||
| 38 | + os.mkdir('sigset') | ||
| 39 | + out = open('sigset/%s.xml' % lfpwType,'w') | ||
| 40 | + print >> out, xmlRoot.toprettyxml() | ||
| 41 | + out.close() | ||
| 42 | + | ||
| 43 | + |