Commit a8c8f400f8a1417ba4f66d06959b08adc99e0e60

Authored by Scott Klum
1 parent 924b5866

Added option to use maximum score of grouped rects instead of sum

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) 439 +void OpenCVUtils::group(QList<Rect> &rects, QList<float> &confidences, float confidenceThreshold, int minNeighbors, float epsilon, bool useMax)
440 { 440 {
441 if (rects.isEmpty()) 441 if (rects.isEmpty())
442 return; 442 return;
@@ -449,7 +449,7 @@ void OpenCVUtils::group(QList&lt;Rect&gt; &amp;rects, QList&lt;float&gt; &amp;confidences, float con @@ -449,7 +449,7 @@ void OpenCVUtils::group(QList&lt;Rect&gt; &amp;rects, QList&lt;float&gt; &amp;confidences, float con
449 449
450 // Total number of rects in each class 450 // Total number of rects in each class
451 vector<int> neighbors(nClasses, 0); 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 for (size_t i = 0; i < labels.size(); i++) 454 for (size_t i = 0; i < labels.size(); i++)
455 { 455 {
@@ -459,7 +459,7 @@ void OpenCVUtils::group(QList&lt;Rect&gt; &amp;rects, QList&lt;float&gt; &amp;confidences, float con @@ -459,7 +459,7 @@ void OpenCVUtils::group(QList&lt;Rect&gt; &amp;rects, QList&lt;float&gt; &amp;confidences, float con
459 rrects[cls].width += rects[i].width; 459 rrects[cls].width += rects[i].width;
460 rrects[cls].height += rects[i].height; 460 rrects[cls].height += rects[i].height;
461 neighbors[cls]++; 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 // Find average rectangle for all classes 465 // Find average rectangle for all classes
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); 105 + void group(QList<cv::Rect> &rects, QList<float> &confidences, float confidenceThreshold, int minNeighbors, float epsilon, bool useMax=false);
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, int degrees, bool rotateMat=true, bool rotatePoints=true, bool rotateRects=true); 108 void rotate(const br::Template &src, br::Template &dst, int degrees, bool rotateMat=true, bool rotatePoints=true, bool rotateRects=true);