diff --git a/openbr/core/opencvutils.cpp b/openbr/core/opencvutils.cpp index 0a44513..7a43f95 100644 --- a/openbr/core/opencvutils.cpp +++ b/openbr/core/opencvutils.cpp @@ -400,7 +400,7 @@ public: }; // TODO: Make sure case where no confidences are inputted works. -void OpenCVUtils::group(vector &rects, vector &confidences, float epsilon) +void OpenCVUtils::group(vector &rects, vector &confidences, float confidenceThreshold, float epsilon) { if (rects.empty()) return; @@ -415,7 +415,7 @@ void OpenCVUtils::group(vector &rects, vector &confidences, float e // Total number of rects in each class vector rweights(nClasses, 0); - vector rejectWeights(nClasses, -std::numeric_limits::max()); + vector rejectWeights(nClasses, -std::numeric_limits::max()); for (int i = 0; i < labels.size(); i++) { @@ -452,8 +452,6 @@ void OpenCVUtils::group(vector &rects, vector &confidences, float e rects.clear(); confidences.clear(); - const double threshold = 2; - // Aggregate by comparing average rectangles against other average rectangels for (int i = 0; i < nClasses; i++) { @@ -462,17 +460,17 @@ void OpenCVUtils::group(vector &rects, vector &confidences, float e // Used to eliminate rectangles with few neighbors in the case of no weights // int n1 = levelWeights ? rejectLevels[i] : rweights[i]; - double w1 = rejectWeights[i]; + float w1 = rejectWeights[i]; // Eliminate rectangle if it doesn't meet confidence criteria - if (w1 <= threshold) + if (w1 <= confidenceThreshold) continue; // filter out small face rectangles inside large rectangles int j; for (j = 0; j < nClasses; j++) { - double w2 = rejectWeights[j]; + float w2 = rejectWeights[j]; if (j == i) continue; @@ -493,7 +491,7 @@ void OpenCVUtils::group(vector &rects, vector &confidences, float e r1.y >= r2.y - dy && r1.x + r1.width <= r2.x + r2.width + dx && r1.y + r1.height <= r2.y + r2.height + dy && - (w2 > std::max(threshold, w1))) + (w2 > std::max(confidenceThreshold, w1))) break; } diff --git a/openbr/core/opencvutils.h b/openbr/core/opencvutils.h index 6d8d762..cd51e70 100644 --- a/openbr/core/opencvutils.h +++ b/openbr/core/opencvutils.h @@ -99,7 +99,7 @@ namespace OpenCVUtils float overlap(const QRectF &rect1, const QRectF &rect2); // Misc - void group(std::vector &rects, std::vector &confidences, float epsilon); + void group(std::vector &rects, std::vector &confidences, float confidenceThreshold, float epsilon); int getFourcc(); } diff --git a/openbr/plugins/imgproc/slidingwindow.cpp b/openbr/plugins/imgproc/slidingwindow.cpp index 0411c68..f678ce4 100644 --- a/openbr/plugins/imgproc/slidingwindow.cpp +++ b/openbr/plugins/imgproc/slidingwindow.cpp @@ -40,6 +40,7 @@ class SlidingWindowTransform : public MetaTransform Q_PROPERTY(int maxSize READ get_maxSize WRITE set_maxSize RESET reset_maxSize STORED false) Q_PROPERTY(float scaleFactor READ get_scaleFactor WRITE set_scaleFactor RESET reset_scaleFactor STORED false) Q_PROPERTY(int minNeighbors READ get_minNeighbors WRITE set_minNeighbors RESET reset_minNeighbors STORED false) + Q_PROPERTY(float confidenceThreshold READ get_confidenceThreshold WRITE set_confidenceThreshold RESET reset_confidenceThreshold STORED false) Q_PROPERTY(float eps READ get_eps WRITE set_eps RESET reset_eps STORED false) Q_PROPERTY(QString model READ get_model WRITE set_model RESET reset_model STORED false) @@ -49,6 +50,7 @@ class SlidingWindowTransform : public MetaTransform BR_PROPERTY(int, maxSize, -1) BR_PROPERTY(float, scaleFactor, 1.2) BR_PROPERTY(int, minNeighbors, 5) + BR_PROPERTY(float, confidenceThreshold, 2) BR_PROPERTY(float, eps, 0.2) BR_PROPERTY(QString, model, "") @@ -132,7 +134,7 @@ class SlidingWindowTransform : public MetaTransform } } - OpenCVUtils::group(rects, confidences, eps); + OpenCVUtils::group(rects, confidences, confidenceThreshold, eps); if (!enrollAll && rects.empty()) rects.push_back(Rect(0, 0, m.cols, m.rows));