GestureRecognitionToolkit  Version: 0.2.5
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  FeatureExtraction( const std::string id = "" );
46 
50  virtual ~FeatureExtraction();
51 
58  virtual bool deepCopyFrom(const FeatureExtraction *rhs){ return false; };
59 
66  bool copyBaseVariables(const FeatureExtraction *featureExtractionModule);
67 
75  virtual bool computeFeatures(const VectorFloat &inputVector){ return false; }
76 
84  virtual bool computeFeatures(const MatrixFloat &inputMatrix){ return false; }
85 
91  virtual bool clear() override;
92 
98  bool getInitialized() const;
99 
105  bool getFeatureDataReady() const;
106 
112  const VectorFloat& getFeatureVector() const;
113 
119  const MatrixFloat& getFeatureMatrix() const;
120 
124  typedef std::map< std::string, FeatureExtraction*(*)() > StringFeatureExtractionMap;
125 
126  /*
127  Creates a new feature extraction instance based on the input string (which should contain the name of a valid feature extraction such as FFT).
128 
129  @param id: the name of the feature extraction module
130  @return a pointer to the new instance of the feature extraction
131  */
132  static FeatureExtraction* create( const std::string &id );
133 
139  FeatureExtraction* create() const;
140 
141  using MLBase::save;
142  using MLBase::load;
143 
144  GRT_DEPRECATED_MSG( "createNewInstance is deprecated, use create() instead.", FeatureExtraction* createNewInstance() const );
145  GRT_DEPRECATED_MSG( "createInstanceFromString(id) is deprecated, use create(id) instead.", static FeatureExtraction* createInstanceFromString( const std::string &id ) );
146  GRT_DEPRECATED_MSG( "getFeatureExtractionType is deprecated, use getId() instead", std::string getFeatureExtractionType() const );
147 
148 protected:
154  bool init();
155 
161  bool saveFeatureExtractionSettingsToFile( std::fstream &file ) const;
162 
168  bool loadFeatureExtractionSettingsFromFile( std::fstream &file );
169 
170  std::string featureExtractionType;
171  bool initialized;
172  bool featureDataReady;
173  VectorFloat featureVector;
174  MatrixFloat featureMatrix;
175 
176  static StringFeatureExtractionMap *getMap() {
177  if( !stringFeatureExtractionMap ){ stringFeatureExtractionMap = new StringFeatureExtractionMap; }
178  return stringFeatureExtractionMap;
179  }
180 
181 private:
182  static StringFeatureExtractionMap *stringFeatureExtractionMap;
183  static UINT numFeatureExtractionInstances;
184 
185 };
186 
187 template< typename T > FeatureExtraction *createNewFeatureExtractionModule() { return new T; }
188 
189 template< typename T >
191 public:
192  RegisterFeatureExtractionModule( const std::string &newModuleId ) {
193  getMap()->insert( std::pair< std::string, FeatureExtraction*(*)()>(newModuleId, &createNewFeatureExtractionModule< T > ) );
194  }
195 };
196 
197 GRT_END_NAMESPACE
198 
199 #endif //GRT_FEATURE_EXTRACTION_HEADER
std::map< std::string, FeatureExtraction *(*)() > StringFeatureExtractionMap
virtual bool save(const std::string &filename) const
Definition: MLBase.cpp:167
virtual bool computeFeatures(const MatrixFloat &inputMatrix)
virtual bool computeFeatures(const VectorFloat &inputVector)
FeatureExtraction * createNewFeatureExtractionModule()
Returns a pointer to a new instance of the template class, the caller is responsible for deleting the...
virtual bool clear()
Definition: MLBase.cpp:149
GRT_DEPRECATED_MSG("saveModelToFile(std::string filename) is deprecated, use save(const std::string &filename) instead", virtual bool saveModelToFile(const std::string &filename) const )
virtual bool load(const std::string &filename)
Definition: MLBase.cpp:190
This is the main base class that all GRT machine learning algorithms should inherit from...
Definition: MLBase.h:72
virtual bool deepCopyFrom(const FeatureExtraction *rhs)