Commit 8a62b8b45caa0b9f7dc9b632e278b6b5ad7a0e22
1 parent
41b40786
group cleanup
Showing
1 changed file
with
3 additions
and
18 deletions
openbr/core/opencvutils.cpp
| ... | ... | @@ -441,8 +441,6 @@ void OpenCVUtils::group(QList<Rect> &rects, QList<float> &confidences, float con |
| 441 | 441 | if (rects.isEmpty()) |
| 442 | 442 | return; |
| 443 | 443 | |
| 444 | - const bool useConfidences = !confidences.isEmpty(); | |
| 445 | - | |
| 446 | 444 | vector<int> labels; |
| 447 | 445 | int nClasses = cv::partition(rects.toVector().toStdVector(), labels, SimilarRects(epsilon)); |
| 448 | 446 | |
| ... | ... | @@ -452,7 +450,6 @@ void OpenCVUtils::group(QList<Rect> &rects, QList<float> &confidences, float con |
| 452 | 450 | // Total number of rects in each class |
| 453 | 451 | vector<int> neighbors(nClasses, 0); |
| 454 | 452 | vector<float> classConfidence(nClasses, 0); |
| 455 | - vector<float> rejectWeights(nClasses, -std::numeric_limits<float>::max()); | |
| 456 | 453 | |
| 457 | 454 | for (size_t i = 0; i < labels.size(); i++) |
| 458 | 455 | { |
| ... | ... | @@ -465,17 +462,6 @@ void OpenCVUtils::group(QList<Rect> &rects, QList<float> &confidences, float con |
| 465 | 462 | classConfidence[cls] += confidences[i]; |
| 466 | 463 | } |
| 467 | 464 | |
| 468 | - if (useConfidences) | |
| 469 | - { | |
| 470 | - // For each class, find maximum confidence | |
| 471 | - for (size_t i = 0; i < labels.size(); i++) | |
| 472 | - { | |
| 473 | - int cls = labels[i]; | |
| 474 | - if (confidences[i] > rejectWeights[cls]) | |
| 475 | - rejectWeights[cls] = confidences[i]; | |
| 476 | - } | |
| 477 | - } | |
| 478 | - | |
| 479 | 465 | // Find average rectangle for all classes |
| 480 | 466 | for (int i = 0; i < nClasses; i++) |
| 481 | 467 | { |
| ... | ... | @@ -497,7 +483,7 @@ void OpenCVUtils::group(QList<Rect> &rects, QList<float> &confidences, float con |
| 497 | 483 | Rect r1 = rrects[i]; |
| 498 | 484 | |
| 499 | 485 | // Used to eliminate rectangles with few neighbors in the case of no weights |
| 500 | - const float w1 = rejectWeights[i]; | |
| 486 | + const float w1 = classConfidence[i]; | |
| 501 | 487 | |
| 502 | 488 | // Eliminate rectangle if it doesn't meet confidence criteria |
| 503 | 489 | if (w1 < confidenceThreshold) |
| ... | ... | @@ -520,7 +506,7 @@ void OpenCVUtils::group(QList<Rect> &rects, QList<float> &confidences, float con |
| 520 | 506 | int dx = saturate_cast<int>(r2.width * epsilon); |
| 521 | 507 | int dy = saturate_cast<int>(r2.height * epsilon); |
| 522 | 508 | |
| 523 | - float w2 = rejectWeights[j]; | |
| 509 | + float w2 = classConfidence[j]; | |
| 524 | 510 | |
| 525 | 511 | // If, r1 is within the r2 AND |
| 526 | 512 | // r2 has a higher confidence than r1 |
| ... | ... | @@ -536,8 +522,7 @@ void OpenCVUtils::group(QList<Rect> &rects, QList<float> &confidences, float con |
| 536 | 522 | if( j == nClasses ) |
| 537 | 523 | { |
| 538 | 524 | rects.append(r1); |
| 539 | - if (useConfidences) | |
| 540 | - confidences.append(classConfidence[i]); | |
| 525 | + confidences.append(w1); | |
| 541 | 526 | } |
| 542 | 527 | } |
| 543 | 528 | } | ... | ... |