X-Boost  2.3.8
GroupRectangles.h
Go to the documentation of this file.
1 /* XBoost: Ada-Boost and Friends on Haar/ICF/HOG Features, Library and ToolBox
2  *
3  * Copyright (c) 2008-2014 Paolo Medici <medici@ce.unipr.it>
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the
17  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18  * Boston, MA 02111-1307, USA.
19  */
20 
21 #ifndef _GROUP_RECTANGLES_H
22 #define _GROUP_RECTANGLES_H
23 
24 // TODO: questa libreria deve essere generalizzata
25 
30 #include "Types.h"
31 #include <algorithm>
32 #include <iterator>
33 #include <vector>
34 
36 
37 #define gr_verbose false
38 
39 
41 void groupRectanglesOverlapped(std::vector<Candidate>::iterator first, std::vector<Candidate>::iterator last, float m_groupThreshold )
42 {
43  for(std::vector<Candidate>::iterator i1=first; i1!=last; ++i1)
44  i1->grouped = false;
45 
46  std::vector<float> overlapped;
47  overlapped.reserve((std::distance(first, last)*(std::distance(first, last)-1))/2);
48 
49  // calcolo tutte le sovrapposizioni (tutti contro tutti: non faccio la matrice quadrata dato che e simmetrica, mi basta il triangolo inferiore)
50  for(std::vector<Candidate>::iterator i1=first; i1!=last; ++i1)
51  for(std::vector<Candidate>::iterator i2=i1; ++i2!=last; ) {
52  //calcolo overlap
53  double rect1_area = i1->box.width()*i1->box.height();
54  double rect2_area = i2->box.width()*i2->box.height();
55 
56  if( std::min(rect1_area, rect2_area) > 0.3 * std::max(rect1_area, rect2_area) )
57  overlapped.push_back( boxoverlap(i1->box, i2->box, Overlap_On_Min ) );
58  else
59  overlapped.push_back( boxoverlap(i1->box, i2->box, Overlap_On_Max ) );
60  }
61 
62  // quando la percentuale di sovrapposizione supera la soglia..
63  // ..e almeno uno dei due non e stato ancora raggruppato
64  // li raggruppo
65  std::vector<float>::iterator area = overlapped.begin();
66  for(std::vector<Candidate>::iterator i1=first; i1!=last; ++i1)
67  for(std::vector<Candidate>::iterator i2=i1; ++i2!=last; ++area)
68  if(*area > m_groupThreshold && (!i1->grouped || !i2->grouped))
69  {
70  if(i1->response < i2->response)
71  i1->grouped = true;
72  else
73  i2->grouped = true;
74  }
75 }
76 
78 void groupRectanglesOverlapped(std::vector<Candidate> & out, float m_groupThreshold )
79 {
80  groupRectanglesOverlapped(out.begin(), out.end(), m_groupThreshold);
81 }
82 
83 #endif
Types involved in boosting.
double boxoverlap(rect a, rect b, OverlapCriterion criterion=Overlap_On_Union)
get overlapped area
void groupRectanglesOverlapped(std::vector< Candidate >::iterator first, std::vector< Candidate >::iterator last, float m_groupThreshold)
metodo per segnare come non-candidati i rettangoli sovrapposti piu' di una determinata soglia ...
Definition: GroupRectangles.h:41