Commit 560e477d6bd6f2d6139612e19c3f4fe0095e8b8b
1 parent
52dc5736
Option to ignore border on sliding window
Showing
1 changed file
with
13 additions
and
1 deletions
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,6 +63,16 @@ private: | @@ -61,6 +63,16 @@ 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 | + | ||
| 67 | + if (ignoreBorder > 0) { | ||
| 68 | + foreach (Template t , data) { | ||
| 69 | + if (t.file.get<QString>("Label") == "pos") { | ||
| 70 | + Mat m = t.m(); | ||
| 71 | + t = Mat(m,Rect(ignoreBorder,ignoreBorder,m.cols - ignoreBorder, m.rows - ignoreBorder)); | ||
| 72 | + } | ||
| 73 | + } | ||
| 74 | + } | ||
| 75 | + | ||
| 64 | if (transform->trainable) { | 76 | if (transform->trainable) { |
| 65 | transform->train(data); | 77 | transform->train(data); |
| 66 | } | 78 | } |
| @@ -101,7 +113,7 @@ protected: | @@ -101,7 +113,7 @@ protected: | ||
| 101 | foreach (const Template &t, src) { | 113 | foreach (const Template &t, src) { |
| 102 | for (float y = 0; y + windowHeight < t.m().rows; y += windowHeight*stepFraction) { | 114 | 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) { | 115 | for (float x = 0; x + windowWidth < t.m().cols; x += windowWidth*stepFraction) { |
| 104 | - Mat windowMat(t.m(), Rect(x, y, windowWidth, windowHeight)); | 116 | + Mat windowMat(t.m(), Rect(x + ignoreBorder, y + ignoreBorder, windowWidth - ignoreBorder, windowHeight - ignoreBorder)); |
| 105 | Template detect; | 117 | Template detect; |
| 106 | transform->project(Template(t.file, windowMat), detect); | 118 | transform->project(Template(t.file, windowMat), detect); |
| 107 | 119 |