GestureRecognitionToolkit  Version: 0.2.0
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 GRT_BEGIN_NAMESPACE
37 
38 class GRT_API 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 VectorFloat &inputVector){ return false; }
75 
83  virtual bool computeFeatures(const MatrixFloat &inputMatrix){ return false; }
84 
91  virtual bool reset(){ return true; }
92 
98  virtual bool clear();
99 
107  virtual bool saveModelToFile( std::fstream &file ) const{ return false; }
108 
116  virtual bool loadModelFromFile( std::fstream &file ){ return false; }
117 
123  std::string getFeatureExtractionType() const;
124 
130  UINT getNumInputDimensions() const;
131 
137  UINT getNumOutputDimensions() const;
138 
144  bool getInitialized() const;
145 
151  bool getFeatureDataReady() const;
152 
158  const VectorFloat& getFeatureVector() const;
159 
165  const MatrixFloat& getFeatureMatrix() const;
166 
170  typedef std::map< std::string, FeatureExtraction*(*)() > StringFeatureExtractionMap;
171 
172  /*
173  Creates a new feature extraction instance based on the input string (which should contain the name of a valid feature extraction such as FFT).
174 
175  @param featureExtractionType: the name of the feature extraction module
176  @return FeatureExtraction*: a pointer to the new instance of the feature extraction
177  */
178  static FeatureExtraction* createInstanceFromString( const std::string &featureExtractionType );
179 
185  FeatureExtraction* createNewInstance() const;
186 
187  using MLBase::saveModelToFile;
188  using MLBase::loadModelFromFile;
189 
190 protected:
196  bool init();
197 
203  bool saveFeatureExtractionSettingsToFile( std::fstream &file ) const;
204 
210  bool loadFeatureExtractionSettingsFromFile( std::fstream &file );
211 
212  std::string featureExtractionType;
213  bool initialized;
214  bool featureDataReady;
215  VectorFloat featureVector;
216  MatrixFloat featureMatrix;
217 
218  static StringFeatureExtractionMap *getMap() {
219  if( !stringFeatureExtractionMap ){ stringFeatureExtractionMap = new StringFeatureExtractionMap; }
220  return stringFeatureExtractionMap;
221  }
222 
223 private:
224  static StringFeatureExtractionMap *stringFeatureExtractionMap;
225  static UINT numFeatureExtractionInstances;
226 
227 };
228 
229 //These two functions/classes are used to register any new FeatureExtraction Module with the FeatureExtraction base class
230 template< typename T > FeatureExtraction *newFeatureExtractionModuleInstance() { return new T; }
231 
232 template< typename T >
234 public:
235  RegisterFeatureExtractionModule( const std::string &newFeatureExtractionModuleName ) {
236  getMap()->insert( std::pair< std::string, FeatureExtraction*(*)()>(newFeatureExtractionModuleName, &newFeatureExtractionModuleInstance< T > ) );
237  }
238 };
239 
240 GRT_END_NAMESPACE
241 
242 #endif //GRT_FEATURE_EXTRACTION_HEADER
std::map< std::string, FeatureExtraction *(*)() > StringFeatureExtractionMap
virtual bool saveModelToFile(std::fstream &file) const
virtual bool loadModelFromFile(std::fstream &file)
UINT getNumOutputDimensions() const
Definition: MLBase.cpp:214
virtual bool computeFeatures(const MatrixFloat &inputMatrix)
virtual bool computeFeatures(const VectorFloat &inputVector)
virtual bool reset()
This is the main base class that all GRT machine learning algorithms should inherit from...
virtual bool clear()
Definition: MLBase.cpp:127
UINT getNumInputDimensions() const
Definition: MLBase.cpp:212
Definition: MLBase.h:70
virtual bool deepCopyFrom(const FeatureExtraction *rhs)