diff --git a/openbr/openbr_plugin.h b/openbr/openbr_plugin.h index 3a5109e..8e25c2d 100644 --- a/openbr/openbr_plugin.h +++ b/openbr/openbr_plugin.h @@ -1422,7 +1422,7 @@ public: static Classifier *make(QString str, QObject *parent); /*!< \brief Make a classifier from a string. */ virtual void train(const QList &images, const QList &labels) = 0; - virtual float classify(const cv::Mat &image, float *confidence = NULL) const = 0; + virtual float classify(const cv::Mat &image, bool process = true, float *confidence = NULL) const = 0; // Slots for representation virtual cv::Mat preprocess(const cv::Mat &image) const = 0; diff --git a/openbr/plugins/classification/boostedforest.cpp b/openbr/plugins/classification/boostedforest.cpp index 6baa6e1..0ad21d6 100644 --- a/openbr/plugins/classification/boostedforest.cpp +++ b/openbr/plugins/classification/boostedforest.cpp @@ -129,18 +129,24 @@ class BoostedForestClassifier : public Classifier } } - float classify(const Mat &image, float *confidence) const + float classify(const Mat &image, bool process, float *confidence) const { + Mat m; + if (process) + m = preprocess(image); + else + m = image; + float sum = 0; for (int i = 0; i < classifiers.size(); i++) { Node *node = classifiers[i]; while (node->left) { if (representation->maxCatCount() > 1) { - int c = (int)representation->evaluate(image, node->featureIdx); + int c = (int)representation->evaluate(m, node->featureIdx); node = (node->subset[c >> 5] & (1 << (c & 31))) ? node->left : node->right; } else { - double val = representation->evaluate(image, node->featureIdx); + double val = representation->evaluate(m, node->featureIdx); node = val <= node->threshold ? node->left : node->right; } } diff --git a/openbr/plugins/classification/cascade.cpp b/openbr/plugins/classification/cascade.cpp index 59c9983..48ab310 100644 --- a/openbr/plugins/classification/cascade.cpp +++ b/openbr/plugins/classification/cascade.cpp @@ -152,11 +152,11 @@ class CascadeClassifier : public Classifier } } - float classify(const Mat &image, float *confidence) const + float classify(const Mat &image, bool process, float *confidence) const { float stageConf = 0.0f; foreach (const Classifier *stage, stages) { - float result = stage->classify(image, &stageConf); + float result = stage->classify(image, process, &stageConf); if (result == 0.0f) { if (confidence) *confidence += stageConf; @@ -219,7 +219,7 @@ private: if (!imgHandler.getPos(pos)) qFatal("Cannot get another positive sample!"); - if (classify(pos, &confidence) > 0.0f) { + if (classify(pos, true, &confidence) > 0.0f) { printf("POS current samples: %d\r", images.size()); images.append(pos); labels.append(1.0f); @@ -235,7 +235,7 @@ private: if (!imgHandler.getNeg(neg)) qFatal("Cannot get another negative sample!"); - if (classify(neg, &confidence) > 0.0f) { + if (classify(neg, true, &confidence) > 0.0f) { printf("NEG current samples: %d\r", images.size() - posCount); images.append(neg); labels.append(0.0f); diff --git a/openbr/plugins/imgproc/slidingwindow.cpp b/openbr/plugins/imgproc/slidingwindow.cpp index 7049711..1009a51 100644 --- a/openbr/plugins/imgproc/slidingwindow.cpp +++ b/openbr/plugins/imgproc/slidingwindow.cpp @@ -53,12 +53,6 @@ class SlidingWindowTransform : public MetaTransform BR_PROPERTY(QString, model, "") - void init() - { - QDataStream stream; - load(stream); - } - void train(const TemplateList &data) { classifier->train(data.data(), File::get(data, "Label", -1)); @@ -90,8 +84,7 @@ class SlidingWindowTransform : public MetaTransform Mat m; OpenCVUtils::cvtUChar(t[i], m); std::vector rects; - std::vector rejectLevels; - std::vector levelWeights; + std::vector confidences; if (maxObjectSize.height == 0 || maxObjectSize.width == 0) maxObjectSize = m.size(); @@ -123,21 +116,23 @@ class SlidingWindowTransform : public MetaTransform for (int x = 0; x < processingRectSize.width; x += step) { Mat window = repImage(Rect(Point(x, y), Size(originalWindowSize.width + dx, originalWindowSize.height + dy))).clone(); - float gypWeight; - int result = classifier->classify(window, &gypWeight); + float confidence; + int result = classifier->classify(window, false, &confidence); - if (12 - result < 4) { + if (result == 1) { rects.push_back(Rect(cvRound(x*factor), cvRound(y*factor), windowSize.width, windowSize.height)); - rejectLevels.push_back(result); - levelWeights.push_back(gypWeight); + confidences.push_back(confidence); } + // Add ROC mode + if (result == 0) x += step; } } } + // groupRectangles(rects, confidences, eps); groupRectangles(rects, rejectLevels, levelWeights, minNeighbors, eps); if (!enrollAll && rects.empty())