Commit c1dcf40ea5aeba77a49f203b3f2855ce9904e94a

Authored by Brendan Klare
1 parent 0d5075e0

Speed ups and minor tweaks to sliding window

openbr/plugins/lbp.cpp
... ... @@ -15,6 +15,7 @@
15 15 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
16 16  
17 17 #include <opencv2/imgproc/imgproc.hpp>
  18 +#include <opencv2/highgui/highgui.hpp>
18 19 #include <limits>
19 20 #include "openbr_internal.h"
20 21  
... ... @@ -30,6 +31,7 @@ namespace br
30 31 * Pattern Analysis and Machine Intelligence, IEEE Transactions, vol.28, no.12, pp.2037-2041, Dec. 2006
31 32 * \author Josh Klontz \cite jklontz
32 33 */
  34 +static int SCNT = 1;
33 35 class LBPTransform : public UntrainableTransform
34 36 {
35 37 Q_OBJECT
... ... @@ -98,7 +100,6 @@ class LBPTransform : public UntrainableTransform
98 100 void project(const Template &src, Template &dst) const
99 101 {
100 102 Mat m; src.m().convertTo(m, CV_32F); assert(m.isContinuous() && (m.channels() == 1));
101   -
102 103 Mat n(m.rows, m.cols, CV_8UC1);
103 104 n = null; // Initialize to NULL LBP pattern
104 105  
... ...
openbr/plugins/slidingwindow.cpp
... ... @@ -75,6 +75,7 @@ private:
75 75 dst.file.clearRects();
76 76 float scale = src.file.get<float>("scale", 1);
77 77 Template windowTemplate(src.file, src);
  78 + QList<float> confidences = dst.file.getList<float>("Confidences", QList<float>());
78 79 for (double y = 0; y + windowHeight < src.m().rows; y += stepSize) {
79 80 for (double x = 0; x + windowWidth < src.m().cols; x += stepSize) {
80 81 Mat windowMat(src, Rect(x, y, windowWidth, windowHeight));
... ... @@ -86,14 +87,13 @@ private:
86 87 // the result will be in the Label
87 88 if (conf > threshold) {
88 89 dst.file.appendRect(QRectF((float) x * scale, (float) y * scale, (float) windowWidth * scale, (float) windowHeight * scale));
89   - QList<float> confidences = dst.file.getList<float>("Confidences", QList<float>());
90 90 confidences.append(conf);
91   - dst.file.setList<float>("Confidences", confidences);
92 91 if (takeFirst)
93 92 return;
94 93 }
95 94 }
96 95 }
  96 + dst.file.setList<float>("Confidences", confidences);
97 97 }
98 98 };
99 99  
... ... @@ -114,6 +114,7 @@ class BuildScalesTransform : public Transform
114 114 Q_PROPERTY(int negToPosRatio READ get_negToPosRatio WRITE set_negToPosRatio RESET reset_negToPosRatio STORED false)
115 115 Q_PROPERTY(int minSize READ get_minSize WRITE set_minSize RESET reset_minSize STORED false)
116 116 Q_PROPERTY(double maxOverlap READ get_maxOverlap WRITE set_maxOverlap RESET reset_maxOverlap STORED false)
  117 + Q_PROPERTY(float minScale READ get_minScale WRITE set_minScale RESET reset_minScale STORED false)
117 118 Q_PROPERTY(bool negSamples READ get_negSamples WRITE set_negSamples RESET reset_negSamples STORED false)
118 119 BR_PROPERTY(br::Transform *, transform, NULL)
119 120 BR_PROPERTY(double, scaleFactor, 0.75)
... ... @@ -122,6 +123,7 @@ class BuildScalesTransform : public Transform
122 123 BR_PROPERTY(int, negToPosRatio, 1)
123 124 BR_PROPERTY(int, minSize, 8)
124 125 BR_PROPERTY(double, maxOverlap, 0)
  126 + BR_PROPERTY(float, minScale, 1.0)
125 127 BR_PROPERTY(bool, negSamples, true)
126 128  
127 129 public:
... ... @@ -131,14 +133,13 @@ private:
131 133  
132 134 void train(const TemplateList &_data)
133 135 {
134   - TemplateList data = _data; // have to make a copy b/c data is const
  136 + TemplateList data(_data); // have to make a copy b/c data is const
135 137 aspectRatio = getAspectRatio(data);
136 138 data.first().file.set("aspectRatio", aspectRatio);
137 139 windowHeight = (int) qRound((float) windowWidth / aspectRatio);
138 140  
139 141 if (transform->trainable) {
140 142 TemplateList full;
141   -
142 143 foreach (const Template &tmpl, data) {
143 144 QList<Rect> posRects = OpenCVUtils::toRects(tmpl.file.rects());
144 145 QList<Rect> negRects;
... ... @@ -222,7 +223,7 @@ private:
222 223 startScale = qRound((float) rows / (float) windowHeight);
223 224 else
224 225 startScale = qRound((float) cols / (float) windowWidth);
225   - for (float scale = startScale; scale >= 1.0; scale -= (1.0 - scaleFactor)) {
  226 + for (float scale = startScale; scale >= minScale; scale -= (1.0 - scaleFactor)) {
226 227 Template scaleImg(src.file, Mat());
227 228 scaleImg.file.set("scale", scale);
228 229 resize(src, scaleImg, Size(qRound(cols / scale), qRound(rows / scale)));
... ...