GestureRecognitionToolkit  Version: 1.0 Revision: 04-03-15
The Gesture Recognition Toolkit (GRT) is a cross-platform, open-source, c++ machine learning library for real-time gesture recognition.
FeatureExtraction.h
Go to the documentation of this file.
1 
31 #ifndef GRT_FEATURE_EXTRACTION_HEADER
32 #define GRT_FEATURE_EXTRACTION_HEADER
33 
34 #include "MLBase.h"
35 
36 namespace GRT{
37 
38 class FeatureExtraction : public MLBase
39 {
40 public:
45 
49  virtual ~FeatureExtraction();
50 
57  virtual bool deepCopyFrom(const FeatureExtraction *rhs){ return false; };
58 
65  bool copyBaseVariables(const FeatureExtraction *featureExtractionModule);
66 
74  virtual bool computeFeatures(const VectorDouble &inputVector){ return false; }
75 
82  virtual bool reset(){ return true; }
83 
89  virtual bool clear();
90 
98  virtual bool saveModelToFile(fstream &file) const{ return false; }
99 
107  virtual bool loadModelFromFile(fstream &file){ return false; }
108 
114  string getFeatureExtractionType() const;
115 
121  UINT getNumInputDimensions() const;
122 
128  UINT getNumOutputDimensions() const;
129 
135  bool getInitialized() const;
136 
142  bool getFeatureDataReady() const;
143 
149  VectorDouble getFeatureVector() const;
150 
154  typedef std::map< string, FeatureExtraction*(*)() > StringFeatureExtractionMap;
155 
156  /*
157  Creates a new feature extraction instance based on the input string (which should contain the name of a valid feature extraction such as FFT).
158 
159  @param string const &featureExtractionType: the name of the feature extraction module
160  @return FeatureExtraction*: a pointer to the new instance of the feature extraction
161  */
162  static FeatureExtraction* createInstanceFromString(string const &featureExtractionType);
163 
170 
173 
174 protected:
180  bool init();
181 
187  bool saveFeatureExtractionSettingsToFile(fstream &file) const;
188 
194  bool loadFeatureExtractionSettingsFromFile(fstream &file);
195 
196  string featureExtractionType;
197  bool initialized;
198  bool featureDataReady;
199  VectorDouble featureVector;
200 
201  static StringFeatureExtractionMap *getMap() {
202  if( !stringFeatureExtractionMap ){ stringFeatureExtractionMap = new StringFeatureExtractionMap; }
203  return stringFeatureExtractionMap;
204  }
205 
206 private:
207  static StringFeatureExtractionMap *stringFeatureExtractionMap;
208  static UINT numFeatureExtractionInstances;
209 
210 };
211 
212 //These two functions/classes are used to register any new FeatureExtraction Module with the FeatureExtraction base class
213 template< typename T > FeatureExtraction *newFeatureExtractionModuleInstance() { return new T; }
214 
215 template< typename T >
217 public:
218  RegisterFeatureExtractionModule(string const &newFeatureExtractionModuleName) {
219  getMap()->insert( std::pair<string, FeatureExtraction*(*)()>(newFeatureExtractionModuleName, &newFeatureExtractionModuleInstance< T > ) );
220  }
221 };
222 
223 } //End of namespace GRT
224 
225 #endif //GRT_FEATURE_EXTRACTION_HEADER
virtual bool saveModelToFile(string filename) const
Definition: MLBase.cpp:135
virtual bool computeFeatures(const VectorDouble &inputVector)
virtual bool loadModelFromFile(string filename)
Definition: MLBase.cpp:157
std::map< string, FeatureExtraction *(*)() > StringFeatureExtractionMap
Definition: AdaBoost.cpp:25
virtual bool saveModelToFile(fstream &file) const
UINT getNumOutputDimensions() const
VectorDouble getFeatureVector() const
virtual bool loadModelFromFile(fstream &file)
UINT getNumInputDimensions() const
virtual bool deepCopyFrom(const FeatureExtraction *rhs)
string getFeatureExtractionType() const
This is the main base class that all GRT machine learning algorithms should inherit from...
bool loadFeatureExtractionSettingsFromFile(fstream &file)
bool saveFeatureExtractionSettingsToFile(fstream &file) const
FeatureExtraction * createNewInstance() const
bool copyBaseVariables(const FeatureExtraction *featureExtractionModule)