Commit a231cbed0cac8f199d17de0f0c526e81faef922f

Authored by Jordan Cheney
1 parent 98ce6592

Fixed compile bug in store and update windowSize to be more elegant

openbr/core/boost.cpp
... ... @@ -142,7 +142,10 @@ static CvMat* cvPreprocessIndexArray( const CvMat* idx_arr, int data_arr_size, b
142 142 void FeatureEvaluator::init(Representation *_representation, int _maxSampleCount)
143 143 {
144 144 representation = _representation;
145   - data.create((int)_maxSampleCount, representation->postWindowSize().area(), CV_32SC1);
  145 +
  146 + int dx, dy;
  147 + Size windowSize = representation->windowSize(dx, dy);
  148 + data.create((int)_maxSampleCount, Size(windowSize.width + dx, windowSize.height + dy).area(), CV_32SC1);
146 149 cls.create( (int)_maxSampleCount, 1, CV_32FC1 );
147 150 }
148 151  
... ... @@ -150,7 +153,9 @@ void FeatureEvaluator::setImage(const Mat &img, uchar clsLabel, int idx)
150 153 {
151 154 cls.ptr<float>(idx)[0] = clsLabel;
152 155  
153   - Mat integralImg(representation->postWindowSize(), data.type(), data.ptr<int>(idx));
  156 + int dx, dy;
  157 + Size windowSize = representation->windowSize(dx, dy);
  158 + Mat integralImg(Size(windowSize.width + dx, windowSize.height + dy), data.type(), data.ptr<int>(idx));
154 159 representation->preprocess(img, integralImg);
155 160 }
156 161  
... ...
openbr/core/cascade.cpp
... ... @@ -231,7 +231,8 @@ void _CascadeClassifier::detectMultiScale(const Mat&amp; image, vector&lt;Rect&gt;&amp; object
231 231 Mat imageBuffer(image.rows + 1, image.cols + 1, CV_8U);
232 232  
233 233 for (double factor = 1; ; factor *= scaleFactor) {
234   - Size originalWindowSize = representation->preWindowSize();
  234 + int dx, dy;
  235 + Size originalWindowSize = representation->windowSize(dx, dy);
235 236  
236 237 Size windowSize(cvRound(originalWindowSize.width*factor), cvRound(originalWindowSize.height*factor) );
237 238 Size scaledImageSize(cvRound(image.cols/factor ), cvRound(image.rows/factor));
... ... @@ -253,7 +254,7 @@ void _CascadeClassifier::detectMultiScale(const Mat&amp; image, vector&lt;Rect&gt;&amp; object
253 254 int yStep = factor > 2. ? 1 : 2;
254 255 for (int y = 0; y < processingRectSize.height; y += yStep) {
255 256 for (int x = 0; x < processingRectSize.width; x += yStep) {
256   - Mat window = repImage(Rect(Point(x, y), representation->postWindowSize())).clone();
  257 + Mat window = repImage(Rect(Point(x, y), Size(originalWindowSize.width + dx, originalWindowSize.height + dy))).clone();
257 258  
258 259 double gypWeight;
259 260 int result = predict(window, gypWeight);
... ...
openbr/openbr_plugin.h
... ... @@ -1407,8 +1407,7 @@ public:
1407 1407 // and returned.
1408 1408 virtual cv::Mat evaluate(const cv::Mat &image, const QList<int> &indices = QList<int>()) const = 0;
1409 1409  
1410   - virtual cv::Size preWindowSize() const = 0; // window size before preprocessing
1411   - virtual cv::Size postWindowSize() const = 0; // window size after preprocessing
  1410 + virtual cv::Size windowSize(int &dx, int &dy) const = 0; // dx and dy should indicate the change to the original window size after preprocessing
1412 1411 virtual int numFeatures() const = 0;
1413 1412 virtual int maxCatCount() const = 0;
1414 1413 };
... ... @@ -1427,7 +1426,7 @@ public:
1427 1426  
1428 1427 // Slots for representation
1429 1428 virtual cv::Mat preprocess(const cv::Mat &image) const = 0;
1430   - virtual cv::Size windowSize() const = 0;
  1429 + virtual cv::Size windowSize(int &dx, int &dy) const = 0;
1431 1430  
1432 1431 // OpenCV compatibility
1433 1432 virtual int numFeatures() const = 0;
... ...
openbr/plugins/classification/boostedforest.cpp
... ... @@ -167,9 +167,9 @@ class BoostedForestClassifier : public Classifier
167 167 return dst;
168 168 }
169 169  
170   - Size windowSize() const
  170 + Size windowSize(int &dx, int &dy) const
171 171 {
172   - return representation->preWindowSize();
  172 + return representation->windowSize(dx, dy);
173 173 }
174 174  
175 175 void read(const FileNode &node)
... ...
openbr/plugins/classification/cascade.cpp
... ... @@ -186,9 +186,9 @@ class CascadeClassifier : public Classifier
186 186 return stages.first()->preprocess(image);
187 187 }
188 188  
189   - Size windowSize() const
  189 + Size windowSize(int &dx, int &dy) const
190 190 {
191   - return stages.first()->windowSize();
  191 + return stages.first()->windowSize(dx, dy);
192 192 }
193 193  
194 194 void read(const FileNode &node)
... ...
openbr/plugins/imgproc/slidingwindow.cpp
... ... @@ -99,7 +99,8 @@ class SlidingWindowTransform : public MetaTransform
99 99 Mat imageBuffer(m.rows + 1, m.cols + 1, CV_8U);
100 100  
101 101 for (double factor = 1; ; factor *= scaleFactor) {
102   - Size originalWindowSize(24, 24);
  102 + int dx, dy;
  103 + Size originalWindowSize = classifier->windowSize(dx, dy);
103 104  
104 105 Size windowSize(cvRound(originalWindowSize.width*factor), cvRound(originalWindowSize.height*factor) );
105 106 Size scaledImageSize(cvRound(m.cols/factor ), cvRound(m.rows/factor));
... ... @@ -120,7 +121,7 @@ class SlidingWindowTransform : public MetaTransform
120 121 int step = factor > 2. ? 1 : 2;
121 122 for (int y = 0; y < processingRectSize.height; y += step) {
122 123 for (int x = 0; x < processingRectSize.width; x += step) {
123   - Mat window = repImage(Rect(Point(x, y), Size(25,25))).clone();
  124 + Mat window = repImage(Rect(Point(x, y), Size(originalWindowSize.width + dx, originalWindowSize.height + dy))).clone();
124 125  
125 126 float gypWeight;
126 127 int result = classifier->classify(window, gypWeight);
... ... @@ -173,7 +174,7 @@ class SlidingWindowTransform : public MetaTransform
173 174 {
174 175 (void) stream;
175 176  
176   - QString path = Globals->sdkPath + "/share/openbr/models/openbrcascades/" + cascadeDir;
  177 + QString path = Globals->sdkPath + "/share/openbr/models/openbrcascades/" + model;
177 178 QtUtils::touchDir(QDir(path));
178 179  
179 180 QString filename = path + "/cascade.xml";
... ...
openbr/plugins/representation/haar.cpp
... ... @@ -89,8 +89,7 @@ class HaarRepresentation : public Representation
89 89 }
90 90  
91 91 int numFeatures() const { return features.size(); }
92   - Size preWindowSize() const { return Size(winWidth, winHeight); }
93   - Size postWindowSize() const { return Size(winWidth + 1, winHeight + 1); }
  92 + Size windowSize(int &dx, int &dy) const { dx = dy = 1; return Size(winWidth, winHeight); }
94 93 int maxCatCount() const { return 0; }
95 94  
96 95 struct Feature
... ...
openbr/plugins/representation/mblbp.cpp
... ... @@ -58,9 +58,8 @@ class MBLBPRepresentation : public Representation
58 58 return result;
59 59 }
60 60  
  61 + Size windowSize(int &dx, int &dy) const { dx = dy = 1; return Size(winWidth, winHeight); }
61 62 int numFeatures() const { return features.size(); }
62   - Size preWindowSize() const { return Size(winWidth, winHeight); }
63   - Size postWindowSize() const { return Size(winWidth + 1, winHeight + 1); }
64 63 int maxCatCount() const { return 256; }
65 64  
66 65 struct Feature
... ... @@ -77,16 +76,28 @@ class MBLBPRepresentation : public Representation
77 76  
78 77 BR_REGISTER(Representation, MBLBPRepresentation)
79 78  
  79 +static inline void calcOffset(int &p0, int &p1, int &p2, int &p3, Rect rect, int offset)
  80 +{
  81 + /* (x, y) */
  82 + p0 = rect.x + offset * rect.y;
  83 + /* (x + w, y) */
  84 + p1 = rect.x + rect.width + offset * rect.y;
  85 + /* (x + w, y) */
  86 + p2 = rect.x + offset * (rect.y + rect.height);
  87 + /* (x + w, y + h) */
  88 + p3 = rect.x + rect.width + offset * (rect.y + rect.height);
  89 +}
  90 +
80 91 MBLBPRepresentation::Feature::Feature( int offset, int x, int y, int _blockWidth, int _blockHeight )
81 92 {
82 93 Rect tr = rect = cvRect(x, y, _blockWidth, _blockHeight);
83   - CV_SUM_OFFSETS( p[0], p[1], p[4], p[5], tr, offset )
  94 + calcOffset(p[0], p[1], p[4], p[5], tr, offset);
84 95 tr.x += 2*rect.width;
85   - CV_SUM_OFFSETS( p[2], p[3], p[6], p[7], tr, offset )
  96 + calcOffset(p[2], p[3], p[6], p[7], tr, offset);
86 97 tr.y +=2*rect.height;
87   - CV_SUM_OFFSETS( p[10], p[11], p[14], p[15], tr, offset )
  98 + calcOffset(p[10], p[11], p[14], p[15], tr, offset);
88 99 tr.x -= 2*rect.width;
89   - CV_SUM_OFFSETS( p[8], p[9], p[12], p[13], tr, offset )
  100 + calcOffset(p[8], p[9], p[12], p[13], tr, offset);
90 101 }
91 102  
92 103 inline uchar MBLBPRepresentation::Feature::calc(const Mat &img) const
... ...