diff --git a/openbr/core/opencvutils.cpp b/openbr/core/opencvutils.cpp index e3e172f..630e512 100644 --- a/openbr/core/opencvutils.cpp +++ b/openbr/core/opencvutils.cpp @@ -436,7 +436,7 @@ public: }; // TODO: Make sure case where no confidences are inputted works. -void OpenCVUtils::group(QList &rects, QList &confidences, float confidenceThreshold, int minNeighbors, float epsilon, bool useMax) +void OpenCVUtils::group(QList &rects, QList &confidences, float confidenceThreshold, int minNeighbors, float epsilon, bool useMax, QList *maxIndices) { if (rects.isEmpty()) return; @@ -450,6 +450,7 @@ void OpenCVUtils::group(QList &rects, QList &confidences, float con // Total number of rects in each class vector neighbors(nClasses, -1); vector classConfidence(nClasses, useMax ? -std::numeric_limits::max() : 0); + vector classMax(nClasses, 0); for (size_t i = 0; i < labels.size(); i++) { @@ -459,7 +460,13 @@ void OpenCVUtils::group(QList &rects, QList &confidences, float con rrects[cls].width += rects[i].width; rrects[cls].height += rects[i].height; neighbors[cls]++; - classConfidence[cls] = useMax ? std::max(classConfidence[cls], confidences[i]) : classConfidence[cls]+confidences[i]; + if (useMax) { + if (confidences[i] > classConfidence[cls]) { + classConfidence[cls] = confidences[i]; + classMax[cls] = i; + } + } else + classConfidence[cls] += confidences[i]; } // Find average rectangle for all classes @@ -523,6 +530,8 @@ void OpenCVUtils::group(QList &rects, QList &confidences, float con { rects.append(r1); confidences.append(w1); + if (maxIndices) + maxIndices->append(classMax[i]); } } } diff --git a/openbr/core/opencvutils.h b/openbr/core/opencvutils.h index 31dae5f..9aa2571 100644 --- a/openbr/core/opencvutils.h +++ b/openbr/core/opencvutils.h @@ -102,7 +102,7 @@ namespace OpenCVUtils float overlap(const QRectF &rect1, const QRectF &rect2); // Misc - void group(QList &rects, QList &confidences, float confidenceThreshold, int minNeighbors, float epsilon, bool useMax=false); + void group(QList &rects, QList &confidences, float confidenceThreshold, int minNeighbors, float epsilon, bool useMax=false, QList *maxIndices=NULL); void pad(const br::Template &src, br::Template &dst, bool padMat, const QList &padding, bool padPoints, bool padRects, int border=0, int value=0); void pad(const br::TemplateList &src, br::TemplateList &dst, bool padMat, const QList &padding, bool padPoints, bool padRects, int border=0, int value=0); void rotate(const br::Template &src, br::Template &dst, float degrees, bool rotateMat=true, bool rotatePoints=true, bool rotateRects=true);