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