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.
ClassLabelTimeoutFilter.h
Go to the documentation of this file.
1 
35 #ifndef GRT_CLASS_LABEL_TIMEOUT_FILTER_HEADER
36 #define GRT_CLASS_LABEL_TIMEOUT_FILTER_HEADER
37 
38 #include "../Util/GRTCommon.h"
39 #include "../CoreModules/PostProcessing.h"
40 
41 GRT_BEGIN_NAMESPACE
42 
43 class GRT_API ClassLabelAndTimer{
44  public:
46  classLabel = 0;
47  }
48  ClassLabelAndTimer(UINT classLabel,unsigned long timeoutDuration){
49  this->classLabel = classLabel;
50  timer.start(timeoutDuration);
51  }
52 
53  //Setters
54  bool set(UINT classLabel,unsigned long timeoutDuration){
55  if( classLabel > 0 && timeoutDuration > 0 ){
56  this->classLabel = classLabel;
57  timer.start(timeoutDuration);
58  return true;
59  }
60  return false;
61  }
62 
63  //Getters
64  UINT getClassLabel(){ return classLabel; }
65  bool timerReached(){ return timer.timerReached(); }
66  unsigned long getRemainingTime(){ return timer.getMilliSeconds(); }
67 
68  protected:
69  UINT classLabel;
70  Timer timer;
71 };
72 
73 class GRT_API ClassLabelTimeoutFilter : public PostProcessing{
74 public:
75  enum FilterModes{ALL_CLASS_LABELS=0,INDEPENDENT_CLASS_LABELS};
76 
97  ClassLabelTimeoutFilter(const unsigned long timeoutDuration = 1000,const UINT filterMode = ALL_CLASS_LABELS);
98 
107 
111  virtual ~ClassLabelTimeoutFilter();
112 
119  ClassLabelTimeoutFilter& operator=(const ClassLabelTimeoutFilter &rhs);
120 
129  virtual bool deepCopyFrom(const PostProcessing *postProcessing) override;
130 
139  virtual bool process(const VectorDouble &inputVector) override;
140 
148  virtual bool reset() override;
149 
157  virtual bool save( std::fstream &file ) const override;
158 
166  virtual bool load( std::fstream &file ) override;
167 
175  bool init(const unsigned long timeoutDuration,const UINT filterMode = ALL_CLASS_LABELS);
176 
183  UINT filter(const UINT predictedClassLabel);
184 
190  UINT getFilteredClassLabel() const { return filteredClassLabel; }
191 
197  bool isTimeoutActive();
198 
211  bool setTimeoutDuration(const unsigned long timeoutDuration);
212 
232  bool setFilterMode(const UINT filterMode);
233 
239  static std::string getId();
240 
241  //Tell the compiler we are using the following functions from the MLBase class to stop hidden virtual function warnings
242  using MLBase::save;
243  using MLBase::load;
244 
245 protected:
246  UINT filteredClassLabel;
247  UINT filterMode;
248  unsigned long timeoutDuration;
249  Vector< ClassLabelAndTimer > classLabelTimers;
250 
251 private:
252  static const std::string id;
254 };
255 
256 GRT_END_NAMESPACE
257 
258 #endif //GRT_CLASS_LABEL_TIMEOUT_FILTER_HEADER
std::string getId() const
Definition: GRTBase.cpp:85
virtual bool deepCopyFrom(const PostProcessing *postProcessing)
Definition: Timer.h:43
virtual bool reset()
Definition: MLBase.cpp:147
virtual bool process(const VectorFloat &inputVector)
virtual bool save(const std::string &filename) const
Definition: MLBase.cpp:167
This is the main base class that all GRT PostProcessing algorithms should inherit from...
bool init()
virtual bool load(const std::string &filename)
Definition: MLBase.cpp:190