-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathMotionDetector.cxx
77 lines (70 loc) · 1.81 KB
/
MotionDetector.cxx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#include "MotionDetector.hxx"
#include <iostream>
using namespace std;
ISentry::MotionDetector::MotionDetector(MotionState *_tap, const libconfig::Setting& cfg):
tap(_tap),in_motion(false)
{
threshold = cfg["threshold"];
backup_frames = (int)cfg["backup_frames"];
running = false;
}
ISentry::MotionDetector::~MotionDetector()
{
if(in_motion)
{
for(vector<FrameProcessor*>::const_iterator i = children.begin();
i!=children.end();
i++)
{
(*i)->stop();
}
}
}
void ISentry::MotionDetector::addFrame(std::pair<cv::Mat,time_t> &m)
{
if(!running)
return;
if(threshold>0 && tap->getSignals()[0]>threshold)
{
std::cerr << "MOTION!\n";
for(vector<FrameProcessor*>::const_iterator i = children.begin();
i!=children.end();
i++)
{
if(!in_motion)
(*i)->start();
// dump saved frames
if(backup_frames>0)
{
for(deque<std::pair<cv::Mat,time_t> >::reverse_iterator j = buf.rbegin();
j!=buf.rend();
j++)
{
(*i)->addFrame(*j);
}
}
buf.clear();
// And finally current frame
(*i)->addFrame(m);
}
in_motion = true;
} else
{
if(in_motion)
{
for(vector<FrameProcessor*>::const_iterator i = children.begin();
i!=children.end();
i++)
{
(*i)->stop();
}
in_motion = false;
}
if(backup_frames>0)
{
while(buf.size()>=backup_frames)
buf.pop_back();
buf.insert(buf.begin(),m);
}
}
}