6 MovementDetector::MovementDetector(
const UINT numDimensions,
const Float upperThreshold,
const Float lowerThreshold,
const Float gamma,
const UINT searchTimeout ) {
7 classType =
"MovementDetector";
8 infoLog.setProceedingText(
"[MovementDetector]");
9 debugLog.setProceedingText(
"[DEBUG MovementDetector]");
10 errorLog.setProceedingText(
"[ERROR MovementDetector]");
11 trainingLog.setProceedingText(
"[TRAINING MovementDetector]");
12 warningLog.setProceedingText(
"[WARNING MovementDetector]");
14 this->numInputDimensions = numDimensions;
15 this->numOutputDimensions = 1;
16 this->upperThreshold = upperThreshold;
17 this->lowerThreshold = lowerThreshold;
19 this->searchTimeout = searchTimeout;
25 MovementDetector::~MovementDetector(){
31 movementDetected =
false;
32 noMovementDetected =
false;
35 errorLog <<
"predict_(VectorFloat &input) - AdaBoost Model Not Trained!" << std::endl;
39 if( input.size() != numInputDimensions ){
40 errorLog <<
"predict_(VectorFloat &input) - The size of the input vector (" << input.size() <<
") does not match the num features in the model (" << numInputDimensions << std::endl;
47 for(UINT n=0; n<numInputDimensions; n++){
48 x += SQR( input[n] - lastSample[n] );
50 movementIndex = (movementIndex*gamma) + sqrt( x );
58 case SEARCHING_FOR_MOVEMENT:
59 if( movementIndex >= upperThreshold ){
60 movementDetected =
true;
61 state = SEARCHING_FOR_NO_MOVEMENT;
64 case SEARCHING_FOR_NO_MOVEMENT:
65 if( movementIndex < lowerThreshold ){
66 noMovementDetected =
true;
67 state = SEARCH_TIMEOUT;
74 state = SEARCH_TIMEOUT;
96 state = SEARCH_TIMEOUT;
99 movementDetected =
false;
100 noMovementDetected =
false;
109 file <<
"GRT_MOVEMENT_DETECTOR_MODEL_FILE_V1.0\n";
113 errorLog <<
"saveModelToFile(fstream &file) - Failed to save ML base settings to file!" << std::endl;
118 file <<
"SearchTimeout: " << searchTimeout << std::endl;
119 file <<
"UpperThreshold: " << upperThreshold << std::endl;
120 file <<
"LowerThreshold: " << lowerThreshold << std::endl;
121 file <<
"Gamma: " << gamma << std::endl;
132 errorLog <<
"loadModelFromFile(string filename) - Could not open file to load model!" << std::endl;
140 if( word !=
"GRT_MOVEMENT_DETECTOR_MODEL_FILE_V1.0" ){
141 errorLog <<
"loadModelFromFile(fstream &file) - Failed to read file header!" << std::endl;
147 errorLog <<
"loadModelFromFile(string filename) - Failed to load base settings from file!" << std::endl;
152 if( word !=
"SearchTimeout:" ){
153 errorLog <<
"loadModelFromFile(fstream &file) - Failed to read SearchTimeout header!" << std::endl;
156 file >> searchTimeout;
159 if( word !=
"UpperThreshold:" ){
160 errorLog <<
"loadModelFromFile(fstream &file) - Failed to read UpperThreshold header!" << std::endl;
163 file >> upperThreshold;
166 if( word !=
"LowerThreshold:" ){
167 errorLog <<
"loadModelFromFile(fstream &file) - Failed to read LowerThreshold header!" << std::endl;
170 file >> lowerThreshold;
173 if( word !=
"Gamma:" ){
174 errorLog <<
"loadModelFromFile(fstream &file) - Failed to read Gamma header!" << std::endl;
182 Float MovementDetector::getUpperThreshold()
const {
183 return upperThreshold;
186 Float MovementDetector::getLowerThreshold()
const {
187 return lowerThreshold;
190 Float MovementDetector::getMovementIndex()
const {
191 return movementIndex;
194 Float MovementDetector::getGamma()
const {
198 bool MovementDetector::getMovementDetected()
const {
199 return movementDetected;
202 bool MovementDetector::getNoMovementDetect()
const {
203 return noMovementDetected;
206 UINT MovementDetector::getState()
const {
210 UINT MovementDetector::getSearchTimeout()
const {
211 return searchTimeout;
214 bool MovementDetector::setUpperThreshold(
const Float upperThreshold) {
215 this->upperThreshold = upperThreshold;
219 bool MovementDetector::setLowerThreshold(
const Float lowerThreshold) {
220 this->lowerThreshold = lowerThreshold;
224 bool MovementDetector::setGamma(
const Float gamma) {
229 bool MovementDetector::setSearchTimeout(
const UINT searchTimeout){
230 this->searchTimeout = searchTimeout;
bool saveBaseSettingsToFile(std::fstream &file) const
signed long getMilliSeconds()
virtual bool saveModelToFile(std::fstream &file) const
bool loadBaseSettingsFromFile(std::fstream &file)
virtual bool predict_(VectorFloat &input)
virtual bool loadModelFromFile(std::fstream &file)
This class implements a simple movement detection algorithm. This can be used to detect periods of 'l...