2 #define GRT_DLL_EXPORTS
7 MovementDetector::MovementDetector(
const UINT numDimensions,
const Float upperThreshold,
const Float lowerThreshold,
const Float gamma,
const UINT searchTimeout ) {
8 classType =
"MovementDetector";
9 infoLog.setProceedingText(
"[MovementDetector]");
10 debugLog.setProceedingText(
"[DEBUG MovementDetector]");
11 errorLog.setProceedingText(
"[ERROR MovementDetector]");
12 trainingLog.setProceedingText(
"[TRAINING MovementDetector]");
13 warningLog.setProceedingText(
"[WARNING MovementDetector]");
15 this->numInputDimensions = numDimensions;
16 this->numOutputDimensions = 1;
17 this->upperThreshold = upperThreshold;
18 this->lowerThreshold = lowerThreshold;
20 this->searchTimeout = searchTimeout;
26 MovementDetector::~MovementDetector(){
32 movementDetected =
false;
33 noMovementDetected =
false;
36 errorLog <<
"predict_(VectorFloat &input) - AdaBoost Model Not Trained!" << std::endl;
40 if( input.size() != numInputDimensions ){
41 errorLog <<
"predict_(VectorFloat &input) - The size of the input vector (" << input.size() <<
") does not match the num features in the model (" << numInputDimensions << std::endl;
48 for(UINT n=0; n<numInputDimensions; n++){
49 x += SQR( input[n] - lastSample[n] );
51 movementIndex = (movementIndex*gamma) + sqrt( x );
59 case SEARCHING_FOR_MOVEMENT:
60 if( movementIndex >= upperThreshold ){
61 movementDetected =
true;
62 state = SEARCHING_FOR_NO_MOVEMENT;
65 case SEARCHING_FOR_NO_MOVEMENT:
66 if( movementIndex < lowerThreshold ){
67 noMovementDetected =
true;
68 state = SEARCH_TIMEOUT;
75 state = SEARCH_TIMEOUT;
97 state = SEARCH_TIMEOUT;
100 movementDetected =
false;
101 noMovementDetected =
false;
110 file <<
"GRT_MOVEMENT_DETECTOR_MODEL_FILE_V1.0\n";
114 errorLog <<
"save(fstream &file) - Failed to save ML base settings to file!" << std::endl;
119 file <<
"SearchTimeout: " << searchTimeout << std::endl;
120 file <<
"UpperThreshold: " << upperThreshold << std::endl;
121 file <<
"LowerThreshold: " << lowerThreshold << std::endl;
122 file <<
"Gamma: " << gamma << std::endl;
133 errorLog <<
"load(string filename) - Could not open file to load model!" << std::endl;
141 if( word !=
"GRT_MOVEMENT_DETECTOR_MODEL_FILE_V1.0" ){
142 errorLog <<
"load(fstream &file) - Failed to read file header!" << std::endl;
148 errorLog <<
"load(string filename) - Failed to load base settings from file!" << std::endl;
153 if( word !=
"SearchTimeout:" ){
154 errorLog <<
"load(fstream &file) - Failed to read SearchTimeout header!" << std::endl;
157 file >> searchTimeout;
160 if( word !=
"UpperThreshold:" ){
161 errorLog <<
"load(fstream &file) - Failed to read UpperThreshold header!" << std::endl;
164 file >> upperThreshold;
167 if( word !=
"LowerThreshold:" ){
168 errorLog <<
"load(fstream &file) - Failed to read LowerThreshold header!" << std::endl;
171 file >> lowerThreshold;
174 if( word !=
"Gamma:" ){
175 errorLog <<
"load(fstream &file) - Failed to read Gamma header!" << std::endl;
183 Float MovementDetector::getUpperThreshold()
const {
184 return upperThreshold;
187 Float MovementDetector::getLowerThreshold()
const {
188 return lowerThreshold;
191 Float MovementDetector::getMovementIndex()
const {
192 return movementIndex;
195 Float MovementDetector::getGamma()
const {
199 bool MovementDetector::getMovementDetected()
const {
200 return movementDetected;
203 bool MovementDetector::getNoMovementDetect()
const {
204 return noMovementDetected;
207 UINT MovementDetector::getState()
const {
211 UINT MovementDetector::getSearchTimeout()
const {
212 return searchTimeout;
215 bool MovementDetector::setUpperThreshold(
const Float upperThreshold) {
216 this->upperThreshold = upperThreshold;
220 bool MovementDetector::setLowerThreshold(
const Float lowerThreshold) {
221 this->lowerThreshold = lowerThreshold;
225 bool MovementDetector::setGamma(
const Float gamma) {
230 bool MovementDetector::setSearchTimeout(
const UINT searchTimeout){
231 this->searchTimeout = searchTimeout;
bool saveBaseSettingsToFile(std::fstream &file) const
virtual bool load(std::fstream &file)
signed long getMilliSeconds()
virtual bool save(std::fstream &file) const
bool loadBaseSettingsFromFile(std::fstream &file)
virtual bool predict_(VectorFloat &input)
This class implements a simple movement detection algorithm. This can be used to detect periods of 'l...