X-Boost  2.3.8
HaarFeatureGenerators.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 _HAAR_FEATURE_GENERATORS_H
22 #define _HAAR_FEATURE_GENERATORS_H
23 
28 #include "HaarFeatureGenerator.h"
29 
31 typedef bool (* FeatureGenerator_t)(HaarFeature & f, int x, int y, int w, int h, unsigned int pw, unsigned int ph);
32 
35  const char *name;
36  FeatureGenerator_t proc;
37  };
38 
41 
43 extern const char iso_pattern[];
44 extern const char fav_pattern[];
45 
47 extern const char standard_pattern[];
48 
50 const FeatureDescription *findFeature(const char *str);
51 
54  public:
55 
57  unsigned int m_mw,m_mh;
58 
60  unsigned int m_minFeatArea;
61 
63  unsigned int m_minWidth;
64 
66  unsigned int m_step;
67 
69  std::vector<FeatureGenerator_t> m_feats;
70 
71  public:
73  static const char *default_pattern;
74 
75  public:
76  BaseHaarFeatureGenerator(const char *pattern);
77 
79  void SetGeometry(int mw, int mh);
80 
82  void SetFeatureMinArea(int minArea) { m_minFeatArea = minArea; }
84  void SetFeatureMinWidth(int minWidth) { m_minWidth = minWidth; }
85 
87  void SetStep(int step) { m_step = step; }
88 
90  void SetBorder(int border) { }
91 
96  bool generate(HaarFeature & f, int x, int y, int w, int h, int idx);
97 
99  unsigned int W() const { return m_mw; }
100  unsigned int H() const { return m_mh; }
101  unsigned int Size() const { return m_mw*m_mh; }
102 
104  unsigned int Feature() const { return m_feats.size(); }
105 
106 };
107 
110  unsigned int m_featCount;
111 
113  std::vector<HaarFeature> m_features;
114 
115 public:
116 
117  BruteForceFeatureGenerator(const char *pattern) : BaseHaarFeatureGenerator(pattern), m_featCount(0) { }
118  virtual ~BruteForceFeatureGenerator();
119 
120  void SetGeometry(int mw, int mh)
121  {
123  m_features.clear();
124  }
125 
126  void SetFeatureMinArea(int minArea) {
128  m_features.clear();
129  }
130 
131  void Reset();
132 
133  unsigned int Count() const { return m_features.size(); }
134 
136  bool Next(HaarFeature & out);
137 };
138 
142  int m_cur;
143 
145  int m_featRand;
146 
147  public:
148 
149  typedef HaarFeature FeatureType;
150 
151  public:
152  RandomFeatureGenerator(const char *pattern, int nFeat) : BaseHaarFeatureGenerator(pattern), m_cur(0), m_featRand(nFeat) { }
153  virtual ~RandomFeatureGenerator();
154 
155  unsigned int Count() const { return m_featRand; }
156  bool Next(HaarFeature & out);
157  void Reset();
158 };
159 
162 
164  int m_featRand;
165 
167  int m_cur;
168 
169  int m_width;
170  int m_height;
171 
172  int m_minArea;
173 
174  int m_step;
175 
176  public:
177 
178  typedef HaarFeature FeatureType;
179 
180  public:
181 
182  JointSparseGranularFeatureGenerator(int n) : m_featRand(n), m_cur(0), m_minArea(0), m_step(1) { }
184 
185  unsigned int Count() const { return m_featRand; }
186 
187  void SetGeometry(int mw, int mh) { m_width = mw; m_height = mh; }
188 
190  void SetFeatureMinArea(int minArea) { m_minArea = minArea; }
191 
193  void SetStep(int step) { m_step = step; }
194 
196  void SetBorder(int border) { }
197 
199  unsigned int W() const { return m_width; }
200  unsigned int H() const { return m_height; }
201 
203  bool Next(HaarFeature & out);
204  void Reset();
205 };
206 
207 
208 
209 #endif
const char standard_pattern[]
void SetGeometry(int mw, int mh)
Width Height.
Feature FeatureType
The feature type generate by this generator.
Definition: FeatureGenerator.h:41
const FeatureDescription featureDescription[]
a list of feature generator for Haar Feature
unsigned int m_minWidth
min Width/Height
Definition: HaarFeatureGenerators.h:63
A library able to generate any Haar Feature.
Definition: HaarFeatureGenerators.h:109
unsigned int m_mw
pattern size
Definition: HaarFeatureGenerators.h:57
void Reset()
reset any interal counters
bool(* FeatureGenerator_t)(HaarFeature &f, int x, int y, int w, int h, unsigned int pw, unsigned int ph)
Definition: HaarFeatureGenerators.h:31
unsigned int Count() const
return the count of feature available
Definition: HaarFeatureGenerators.h:155
Definition: FeatureGenerator.h:36
This generator, instead of exhaustive, use a Random sampling approach.
Definition: HaarFeatureGenerators.h:161
const FeatureDescription * findFeature(const char *str)
convert from a 2char string to Feature generator
void Reset()
reset any interal counters
void SetStep(int step)
searching step
Definition: HaarFeatureGenerators.h:87
void SetBorder(int border)
set a border around patch (in Haar normally have not meaning)
Definition: HaarFeatureGenerators.h:196
static const char * default_pattern
a default pattern for all features in library
Definition: HaarFeatureGenerators.h:73
const char iso_pattern[]
Default pattern with all iso energetic pattern.
void SetBorder(int border)
set a border around patch (in Haar normally have not meaning)
Definition: HaarFeatureGenerators.h:90
This generator, instead of exhaustive, use a Random sampling approach.
Definition: HaarFeatureGenerators.h:140
unsigned int W() const
Return the generator geometry.
Definition: HaarFeatureGenerators.h:99
unsigned int W() const
Return the generator geometry.
Definition: HaarFeatureGenerators.h:199
this file declare the virtual feature generator for Haar Features
std::vector< FeatureGenerator_t > m_feats
lista di feature generator allocati
Definition: HaarFeatureGenerators.h:69
unsigned int Feature() const
Return the number of feature in the vector.
Definition: HaarFeatureGenerators.h:104
bool generate(HaarFeature &f, int x, int y, int w, int h, int idx)
unsigned int m_minFeatArea
dimensione minima
Definition: HaarFeatureGenerators.h:60
Base Feature Generator for Haar Bases using FeatureGenerator_t.
Definition: HaarFeatureGenerators.h:53
void SetFeatureMinWidth(int minWidth)
Set the minimum feature size.
Definition: HaarFeatureGenerators.h:84
bool Next(HaarFeature &out)
generate a Random Feature
void Reset()
reset any interal counters
Definition: HaarFeatureGenerators.h:34
An haar Feature: a collection of weighted HaarNode.
Definition: HaarFeature.h:63
unsigned int m_step
Step for feature search.
Definition: HaarFeatureGenerators.h:66
void SetStep(int step)
searching step
Definition: HaarFeatureGenerators.h:193
bool Next(HaarFeature &out)
Provide a new feature, or return false.
void SetFeatureMinArea(int minArea)
A constraint on minimum area of a feature (width x height > minArea)
Definition: HaarFeatureGenerators.h:82
void SetFeatureMinArea(int minArea)
A constraint on minimum area of a feature (width x height > minArea)
Definition: HaarFeatureGenerators.h:190
unsigned int Count() const
return the count of feature available
Definition: HaarFeatureGenerators.h:185
unsigned int Count() const
return the count of feature available
Definition: HaarFeatureGenerators.h:133