Commit 4a45642fdbebc83f8064fefad13eeba9d6336a53

Authored by Brendan K
2 parents 93092fdf 885efbb2

Merge pull request #140 from biometrics/windowTraining

IgnoreBorder option for slidingWindow detectors
openbr/plugins/regions.cpp
@@ -372,7 +372,7 @@ class FaceFromEyesTransform : public UntrainableTransform @@ -372,7 +372,7 @@ class FaceFromEyesTransform : public UntrainableTransform
372 BR_PROPERTY(double, widthPadding, 0.7) 372 BR_PROPERTY(double, widthPadding, 0.7)
373 BR_PROPERTY(double, verticalLocation, 0.25) 373 BR_PROPERTY(double, verticalLocation, 0.25)
374 BR_PROPERTY(int, leftEyeIdx, 0) 374 BR_PROPERTY(int, leftEyeIdx, 0)
375 - BR_PROPERTY(int, rightEyeIdx, 0) 375 + BR_PROPERTY(int, rightEyeIdx, 1)
376 376
377 void project(const Template &src, Template &dst) const 377 void project(const Template &src, Template &dst) const
378 { 378 {
@@ -384,8 +384,8 @@ class FaceFromEyesTransform : public UntrainableTransform @@ -384,8 +384,8 @@ class FaceFromEyesTransform : public UntrainableTransform
384 return; 384 return;
385 } 385 }
386 386
387 - QPointF eyeL = src.file.points()[0];  
388 - QPointF eyeR = src.file.points()[1]; 387 + QPointF eyeL = src.file.points()[leftEyeIdx];
  388 + QPointF eyeR = src.file.points()[rightEyeIdx];
389 QPointF eyeCenter((eyeL.x() + eyeR.x()) / 2, (eyeL.y() + eyeR.y()) / 2); 389 QPointF eyeCenter((eyeL.x() + eyeR.x()) / 2, (eyeL.y() + eyeR.y()) / 2);
390 float ipd = sqrt(pow(eyeL.x() - eyeR.x(), 2) + pow(eyeL.y() - eyeR.y(), 2)); 390 float ipd = sqrt(pow(eyeL.x() - eyeR.x(), 2) + pow(eyeL.y() - eyeR.y(), 2));
391 float width = ipd + 2 * widthPadding * ipd; 391 float width = ipd + 2 * widthPadding * ipd;
openbr/plugins/slidingwindow.cpp
@@ -46,11 +46,13 @@ class SlidingWindowTransform : public MetaTransform @@ -46,11 +46,13 @@ class SlidingWindowTransform : public MetaTransform
46 Q_PROPERTY(bool takeFirst READ get_takeFirst WRITE set_takeFirst RESET reset_takeFirst STORED false) 46 Q_PROPERTY(bool takeFirst READ get_takeFirst WRITE set_takeFirst RESET reset_takeFirst STORED false)
47 Q_PROPERTY(float threshold READ get_threshold WRITE set_threshold RESET reset_threshold STORED false) 47 Q_PROPERTY(float threshold READ get_threshold WRITE set_threshold RESET reset_threshold STORED false)
48 Q_PROPERTY(float stepFraction READ get_stepFraction WRITE set_stepFraction RESET reset_stepFraction STORED false) 48 Q_PROPERTY(float stepFraction READ get_stepFraction WRITE set_stepFraction RESET reset_stepFraction STORED false)
  49 + Q_PROPERTY(int ignoreBorder READ get_ignoreBorder WRITE set_ignoreBorder RESET reset_ignoreBorder STORED false)
49 BR_PROPERTY(br::Transform *, transform, NULL) 50 BR_PROPERTY(br::Transform *, transform, NULL)
50 BR_PROPERTY(int, windowWidth, 24) 51 BR_PROPERTY(int, windowWidth, 24)
51 BR_PROPERTY(bool, takeFirst, false) 52 BR_PROPERTY(bool, takeFirst, false)
52 BR_PROPERTY(float, threshold, 0) 53 BR_PROPERTY(float, threshold, 0)
53 BR_PROPERTY(float, stepFraction, 0.25) 54 BR_PROPERTY(float, stepFraction, 0.25)
  55 + BR_PROPERTY(int, ignoreBorder, 0)
54 56
55 private: 57 private:
56 int windowHeight; 58 int windowHeight;
@@ -61,8 +63,17 @@ private: @@ -61,8 +63,17 @@ private:
61 if (aspectRatio == -1) 63 if (aspectRatio == -1)
62 aspectRatio = getAspectRatio(data); 64 aspectRatio = getAspectRatio(data);
63 windowHeight = qRound(windowWidth / aspectRatio); 65 windowHeight = qRound(windowWidth / aspectRatio);
  66 +
64 if (transform->trainable) { 67 if (transform->trainable) {
65 - transform->train(data); 68 + TemplateList dataOut = data;
  69 + if (ignoreBorder > 0) {
  70 + for (int i = 0; i < dataOut.size(); i++) {
  71 + Template t = dataOut.at(i);
  72 + Mat m = t.m();
  73 + dataOut.replace(i,Template(t.file, Mat(m,Rect(ignoreBorder,ignoreBorder,m.cols - ignoreBorder * 2, m.rows - ignoreBorder * 2))));
  74 + }
  75 + }
  76 + transform->train(dataOut);
66 } 77 }
67 } 78 }
68 79
@@ -101,7 +112,7 @@ protected: @@ -101,7 +112,7 @@ protected:
101 foreach (const Template &t, src) { 112 foreach (const Template &t, src) {
102 for (float y = 0; y + windowHeight < t.m().rows; y += windowHeight*stepFraction) { 113 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) { 114 for (float x = 0; x + windowWidth < t.m().cols; x += windowWidth*stepFraction) {
104 - Mat windowMat(t.m(), Rect(x, y, windowWidth, windowHeight)); 115 + Mat windowMat(t.m(), Rect(x + ignoreBorder, y + ignoreBorder, windowWidth - ignoreBorder * 2, windowHeight - ignoreBorder * 2));
105 Template detect; 116 Template detect;
106 transform->project(Template(t.file, windowMat), detect); 117 transform->project(Template(t.file, windowMat), detect);
107 118