Commit 34a914c4851ab0464d418b1db318b45e67fed109

Authored by Scott Klum
1 parent 6a019561

Added max indices to group

openbr/core/opencvutils.cpp
@@ -436,7 +436,7 @@ public: @@ -436,7 +436,7 @@ public:
436 }; 436 };
437 437
438 // TODO: Make sure case where no confidences are inputted works. 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 if (rects.isEmpty()) 441 if (rects.isEmpty())
442 return; 442 return;
@@ -450,6 +450,7 @@ void OpenCVUtils::group(QList&lt;Rect&gt; &amp;rects, QList&lt;float&gt; &amp;confidences, float con @@ -450,6 +450,7 @@ void OpenCVUtils::group(QList&lt;Rect&gt; &amp;rects, QList&lt;float&gt; &amp;confidences, float con
450 // Total number of rects in each class 450 // Total number of rects in each class
451 vector<int> neighbors(nClasses, -1); 451 vector<int> neighbors(nClasses, -1);
452 vector<float> classConfidence(nClasses, useMax ? -std::numeric_limits<float>::max() : 0); 452 vector<float> classConfidence(nClasses, useMax ? -std::numeric_limits<float>::max() : 0);
  453 + vector<int> classMax(nClasses, 0);
453 454
454 for (size_t i = 0; i < labels.size(); i++) 455 for (size_t i = 0; i < labels.size(); i++)
455 { 456 {
@@ -459,7 +460,13 @@ void OpenCVUtils::group(QList&lt;Rect&gt; &amp;rects, QList&lt;float&gt; &amp;confidences, float con @@ -459,7 +460,13 @@ void OpenCVUtils::group(QList&lt;Rect&gt; &amp;rects, QList&lt;float&gt; &amp;confidences, float con
459 rrects[cls].width += rects[i].width; 460 rrects[cls].width += rects[i].width;
460 rrects[cls].height += rects[i].height; 461 rrects[cls].height += rects[i].height;
461 neighbors[cls]++; 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 // Find average rectangle for all classes 472 // Find average rectangle for all classes
@@ -523,6 +530,8 @@ void OpenCVUtils::group(QList&lt;Rect&gt; &amp;rects, QList&lt;float&gt; &amp;confidences, float con @@ -523,6 +530,8 @@ void OpenCVUtils::group(QList&lt;Rect&gt; &amp;rects, QList&lt;float&gt; &amp;confidences, float con
523 { 530 {
524 rects.append(r1); 531 rects.append(r1);
525 confidences.append(w1); 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,7 +102,7 @@ namespace OpenCVUtils
102 float overlap(const QRectF &rect1, const QRectF &rect2); 102 float overlap(const QRectF &rect1, const QRectF &rect2);
103 103
104 // Misc 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 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); 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 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); 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 void rotate(const br::Template &src, br::Template &dst, float degrees, bool rotateMat=true, bool rotatePoints=true, bool rotateRects=true); 108 void rotate(const br::Template &src, br::Template &dst, float degrees, bool rotateMat=true, bool rotatePoints=true, bool rotateRects=true);