cv_utils/src/nms.cc
void ApplyGreedyNonMaximalSuppression(vector<cv::Rect>* boxes,
                                      vector<double>* scores,
                                      double overlapThresh) {
  ROS_ASSERT(boxes);
  ROS_ASSERT(scores);
  ROS_ASSERT(boxes->size() == scores->size());

  // Start by putting the rectangles and scores together in a data
  // structure that we will sort.
  vector<BoxScorePair> sortingBox;
  for (unsigned int i = 0u; i < boxes->size(); ++i) {
    sortingBox.push_back(BoxScorePair((*scores)[i], (*boxes)[i]));
  }

  // Sorts into ascending order
  sort(sortingBox.begin(), sortingBox.end(), BoxScorePairLessThan());

  // Now reset the outputs since we'll fill them as we go
  boxes->clear();
  scores->clear();
  
  // Starting from the highest score, add all those entries that don't
  // overlap with an entry already being returned.
  for (vector<BoxScorePair>::const_reverse_iterator i = sortingBox.rbegin();
       i != sortingBox.rend(); ++i) {
    bool doesOverlap = false;
    for (vector<cv::Rect>::const_iterator j = boxes->begin();
         j != boxes->end(); ++j) {
      if (CalculateOverlap(i->second, *j) > overlapThresh) {
        doesOverlap = true;
        break;
      }
    }

    if (!doesOverlap) {
      boxes->push_back(i->second);
      scores->push_back(i->first);
    }
  }
}
// Greedily does non maximal suppression by taking those bounding
// boxes of highest score and removing those above an area overlap
// threshold.
//
// Inputs:
// locs - Bounding boxes specifying locations. Will be changed in place 
//        so that the non-maximal entries are removed
// scores - Scores of all the bounding boxes in locs. Will be changed in 
//          places so that the non-maximal entries are removed. Must be 
//          the same order as locs.
// overlapThresh - Area overlap threshold for two boxes being similar.
//                 Must be between 0 and 1.0
Greedily does non maximal suppression by taking those bounding
boxes of highest score and removing those above an area overlap
threshold.

Bounding boxes specifying locations. Will be changed in place
so that the non-maximal entries are removed
scores - Scores of all the bounding boxes in locs. Will be changed in
places so that the non-maximal entries are removed. Must be
the same order as locs.
overlapThresh - Area overlap threshold for two boxes being similar.
Must be between 0 and 1.0
Greedily does non maximal suppression by taking those bounding boxes of highest score and removing those above an area overlap threshold . Bounding boxes specifying locations . Will be changed in place so that the non - maximal entries are removed scores - Scores of all the bounding boxes in locs . Will be changed in places so that the non - maximal entries are removed . Must be the same order as locs . overlapThresh - Area overlap threshold for two boxes being similar . Must be between 0 and 1 . 0
void ApplyGreedyNonMaximalSuppression(vector<cv::Rect>* boxes,
                                      vector<double>* scores,
                                      double overlapThresh) {
  ROS_ASSERT(boxes);
  ROS_ASSERT(scores);
  ROS_ASSERT(boxes->size() == scores->size());
  vector<BoxScorePair> sortingBox;
  for (unsigned int i = 0u; i < boxes->size(); ++i) {
    sortingBox.push_back(BoxScorePair((*scores)[i], (*boxes)[i]));
  }
  sort(sortingBox.begin(), sortingBox.end(), BoxScorePairLessThan());
  boxes->clear();
  scores->clear();
  for (vector<BoxScorePair>::const_reverse_iterator i = sortingBox.rbegin();
       i != sortingBox.rend(); ++i) {
    bool doesOverlap = false;
    for (vector<cv::Rect>::const_iterator j = boxes->begin();
         j != boxes->end(); ++j) {
      if (CalculateOverlap(i->second, *j) > overlapThresh) {
        doesOverlap = true;
        break;
      }
    }
    if (!doesOverlap) {
      boxes->push_back(i->second);
      scores->push_back(i->first);
    }
  }
}
void ApplyGreedyNonMaximalSuppression ( vector < cv :: Rect > * boxes , vector < double > * scores , double overlapThresh ) { ROS_ASSERT ( boxes ) ; ROS_ASSERT ( scores ) ; ROS_ASSERT ( boxes -> size ( ) == scores -> size ( ) ) ; vector < BoxScorePair > sortingBox ; for ( unsigned int i = 0u ; i < boxes -> size ( ) ; ++ i ) { sortingBox . push_back ( BoxScorePair ( ( * scores ) [ i ] , ( * boxes ) [ i ] ) ) ; } sort ( sortingBox . begin ( ) , sortingBox . end ( ) , BoxScorePairLessThan ( ) ) ; boxes -> clear ( ) ; scores -> clear ( ) ; for ( vector < BoxScorePair > :: const_reverse_iterator i = sortingBox . rbegin ( ) ; i != sortingBox . rend ( ) ; ++ i ) { bool doesOverlap = false ; for ( vector < cv :: Rect > :: const_iterator j = boxes -> begin ( ) ; j != boxes -> end ( ) ; ++ j ) { if ( CalculateOverlap ( i -> second , * j ) > overlapThresh ) { doesOverlap = true ; break ; } } if ( ! doesOverlap ) { boxes -> push_back ( i -> second ) ; scores -> push_back ( i -> first ) ; } } }
Greedily does non maximal suppression by taking those bounding
boxes of highest score and removing those above an area overlap
threshold.
Greedily does non maximal suppression by taking those bounding boxes of highest score and removing those above an area overlap threshold .
// Start by putting the rectangles and scores together in a data // structure that we will sort. // Sorts into ascending order // Now reset the outputs since we'll fill them as we go // Starting from the highest score, add all those entries that don't // overlap with an entry already being returned.