Commit 34a914c4851ab0464d418b1db318b45e67fed109
1 parent
6a019561
Added max indices to group
Showing
2 changed files
with
12 additions
and
3 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, bool useMax) | |
| 439 | +void OpenCVUtils::group(QList<Rect> &rects, QList<float> &confidences, float confidenceThreshold, int minNeighbors, float epsilon, bool useMax, QList<int> *maxIndices) | |
| 440 | 440 | { |
| 441 | 441 | if (rects.isEmpty()) |
| 442 | 442 | return; |
| ... | ... | @@ -450,6 +450,7 @@ void OpenCVUtils::group(QList<Rect> &rects, QList<float> &confidences, float con |
| 450 | 450 | // Total number of rects in each class |
| 451 | 451 | vector<int> neighbors(nClasses, -1); |
| 452 | 452 | vector<float> classConfidence(nClasses, useMax ? -std::numeric_limits<float>::max() : 0); |
| 453 | + vector<int> classMax(nClasses, 0); | |
| 453 | 454 | |
| 454 | 455 | for (size_t i = 0; i < labels.size(); i++) |
| 455 | 456 | { |
| ... | ... | @@ -459,7 +460,13 @@ void OpenCVUtils::group(QList<Rect> &rects, QList<float> &confidences, float con |
| 459 | 460 | rrects[cls].width += rects[i].width; |
| 460 | 461 | rrects[cls].height += rects[i].height; |
| 461 | 462 | neighbors[cls]++; |
| 462 | - classConfidence[cls] = useMax ? std::max(classConfidence[cls], confidences[i]) : classConfidence[cls]+confidences[i]; | |
| 463 | + if (useMax) { | |
| 464 | + if (confidences[i] > classConfidence[cls]) { | |
| 465 | + classConfidence[cls] = confidences[i]; | |
| 466 | + classMax[cls] = i; | |
| 467 | + } | |
| 468 | + } else | |
| 469 | + classConfidence[cls] += confidences[i]; | |
| 463 | 470 | } |
| 464 | 471 | |
| 465 | 472 | // Find average rectangle for all classes |
| ... | ... | @@ -523,6 +530,8 @@ void OpenCVUtils::group(QList<Rect> &rects, QList<float> &confidences, float con |
| 523 | 530 | { |
| 524 | 531 | rects.append(r1); |
| 525 | 532 | confidences.append(w1); |
| 533 | + if (maxIndices) | |
| 534 | + maxIndices->append(classMax[i]); | |
| 526 | 535 | } |
| 527 | 536 | } |
| 528 | 537 | } | ... | ... |
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, bool useMax=false); | |
| 105 | + void group(QList<cv::Rect> &rects, QList<float> &confidences, float confidenceThreshold, int minNeighbors, float epsilon, bool useMax=false, QList<int> *maxIndices=NULL); | |
| 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, float degrees, bool rotateMat=true, bool rotatePoints=true, bool rotateRects=true); | ... | ... |