Commit a8c8f400f8a1417ba4f66d06959b08adc99e0e60
1 parent
924b5866
Added option to use maximum score of grouped rects instead of sum
Showing
2 changed files
with
4 additions
and
4 deletions
openbr/core/opencvutils.cpp
| ... | ... | @@ -436,7 +436,7 @@ public: |
| 436 | 436 | }; |
| 437 | 437 | |
| 438 | 438 | // TODO: Make sure case where no confidences are inputted works. |
| 439 | -void OpenCVUtils::group(QList<Rect> &rects, QList<float> &confidences, float confidenceThreshold, int minNeighbors, float epsilon) | |
| 439 | +void OpenCVUtils::group(QList<Rect> &rects, QList<float> &confidences, float confidenceThreshold, int minNeighbors, float epsilon, bool useMax) | |
| 440 | 440 | { |
| 441 | 441 | if (rects.isEmpty()) |
| 442 | 442 | return; |
| ... | ... | @@ -449,7 +449,7 @@ void OpenCVUtils::group(QList<Rect> &rects, QList<float> &confidences, float con |
| 449 | 449 | |
| 450 | 450 | // Total number of rects in each class |
| 451 | 451 | vector<int> neighbors(nClasses, 0); |
| 452 | - vector<float> classConfidence(nClasses, 0); | |
| 452 | + vector<float> classConfidence(nClasses, useMax ? -std::numeric_limits<float>::max() : 0); | |
| 453 | 453 | |
| 454 | 454 | for (size_t i = 0; i < labels.size(); i++) |
| 455 | 455 | { |
| ... | ... | @@ -459,7 +459,7 @@ void OpenCVUtils::group(QList<Rect> &rects, QList<float> &confidences, float con |
| 459 | 459 | rrects[cls].width += rects[i].width; |
| 460 | 460 | rrects[cls].height += rects[i].height; |
| 461 | 461 | neighbors[cls]++; |
| 462 | - classConfidence[cls] += confidences[i]; | |
| 462 | + classConfidence[cls] = useMax ? std::max(classConfidence[cls], confidences[i]) : classConfidence[cls]+confidences[i]; | |
| 463 | 463 | } |
| 464 | 464 | |
| 465 | 465 | // Find average rectangle for all classes | ... | ... |
openbr/core/opencvutils.h
| ... | ... | @@ -102,7 +102,7 @@ namespace OpenCVUtils |
| 102 | 102 | float overlap(const QRectF &rect1, const QRectF &rect2); |
| 103 | 103 | |
| 104 | 104 | // Misc |
| 105 | - void group(QList<cv::Rect> &rects, QList<float> &confidences, float confidenceThreshold, int minNeighbors, float epsilon); | |
| 105 | + void group(QList<cv::Rect> &rects, QList<float> &confidences, float confidenceThreshold, int minNeighbors, float epsilon, bool useMax=false); | |
| 106 | 106 | void pad(const br::Template &src, br::Template &dst, bool padMat, const QList<int> &padding, bool padPoints, bool padRects, int border=0, int value=0); |
| 107 | 107 | void pad(const br::TemplateList &src, br::TemplateList &dst, bool padMat, const QList<int> &padding, bool padPoints, bool padRects, int border=0, int value=0); |
| 108 | 108 | void rotate(const br::Template &src, br::Template &dst, int degrees, bool rotateMat=true, bool rotatePoints=true, bool rotateRects=true); | ... | ... |