X-Boost  2.3.8
CollapsedHaarFeature.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 _COLLAPSED_HAAR_FEATURE_H
22 #define _COLLAPSED_HAAR_FEATURE_H
23 
24 #include "HaarFeature.h"
26 #include "_stdint.h"
27 
32 struct CollapsedHaarNode {
35  int sign;
37  int offset;
38 
39 public:
40 
41  CollapsedHaarNode() { }
42  CollapsedHaarNode(int _sign, long _offset) : sign(_sign), offset(_offset) { }
43 
44  inline int operator()(const unsigned int *pIntImage) const {
45  return sign * (int) *((const uint32_t *) ( (const uint8_t *)(pIntImage)+offset ) ) ;
46  }
47 };
48 
51  std::vector<CollapsedHaarNode> m_nodes;
52 
55 public:
56 
57  // TODO:
59 
63  CollapsedHaarFeature(const HaarFeature &src, int scale, long offset, long stride)
64  {
65  m_nodes.resize(src.size());
66  int j=0;
67  for(std::vector<HaarNode>::const_iterator i=src.begin(); i!=src.end(); ++i)
68  {
69  int x = (int)(i->x * scale + scale - 1);
70  int y = (int)(i->y * scale + scale - 1);
71  m_nodes[j].sign = i->sign;
72  m_nodes[j].offset = ( offset + x + y * stride ) * sizeof(uint32_t);
73  ++j;
74  }
75  }
76 
77  CollapsedHaarFeature(const HaarFeature &src, int offset, const IntegralImageParams & p)
78  {
79  m_nodes.resize(src.size());
80  int j=0;
81  for(std::vector<HaarNode>::const_iterator i=src.begin(); i!=src.end(); ++i)
82  {
83  m_nodes[j].sign = i->sign;
84  m_nodes[j].offset = ( offset + i->x + i->y * p.stride ) * sizeof(uint32_t);
85  ++j;
86  }
87  }
88 
89 
91  CollapsedHaarFeature(const HaarFeature &src, long offset, long stride)
92  {
93  m_nodes.resize(src.size());
94  int j=0;
95  for(std::vector<HaarNode>::const_iterator i=src.begin(); i!=src.end(); ++i)
96  {
97  int x = i->x;
98  int y = i->y;
99  m_nodes[j].sign = i->sign;
100  m_nodes[j].offset = ( offset + x + y * stride ) * sizeof(uint32_t);
101  ++j;
102  }
103  }
104 
106  {
107  }
108 
111  {
112  for(std::vector<CollapsedHaarNode>::iterator i=m_nodes.begin(); i!=m_nodes.end(); i++)
113  i->sign = - i->sign;
114  }
115 
116  inline int debug(const unsigned int *pIntImage) const
117  {
118  int sum = 0;
119 // std::cout << "[" << m_nodes[0].offset << "]";
120  for(std::vector<CollapsedHaarNode>::const_iterator i=m_nodes.begin(); i!=m_nodes.end(); i++)
121  sum += (*i)(pIntImage);
122  return sum;
123  }
124 
125 
127  inline int response(const unsigned int *pIntImage) const
128  {
129  int sum = 0;
130  for(std::vector<CollapsedHaarNode>::const_iterator i=m_nodes.begin(); i!=m_nodes.end(); i++)
131  sum += (*i)(pIntImage);
132  return sum;
133  }
134 
135  inline int operator() (const unsigned int *pIntImage) const
136  {
137  return response(pIntImage);
138  }
139 
140 };
141 
142 inline std::ostream & operator << (std::ostream & out, const CollapsedHaarFeature & s)
143 {
144  return out;
145 }
146 
147 #endif
a precomputed HaarNode in order to boost evaluation performance
Definition: CollapsedHaarFeature.h:33
a descritor based on a integral image
CollapsedHaarFeature(const HaarFeature &src, int scale, long offset, long stride)
Definition: CollapsedHaarFeature.h:63
int sign
accumulator
Definition: CollapsedHaarFeature.h:35
an optimized HaarFeature
Definition: CollapsedHaarFeature.h:50
CollapsedHaarFeature(const HaarFeature &src, long offset, long stride)
Definition: CollapsedHaarFeature.h:91
additional typedef, for portability under win32
An haar Feature: a collection of weighted HaarNode.
Definition: HaarFeature.h:63
parameters required to access to integral image and to create features
Definition: IntegralImageData.h:31
void invert_polarity()
invert the sign of haar nodes (in order to simplify the decision stump)
Definition: CollapsedHaarFeature.h:110
int offset
offset
Definition: CollapsedHaarFeature.h:37
int response(const unsigned int *pIntImage) const
compute the response
Definition: CollapsedHaarFeature.h:127