-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgesturedetector.cpp
More file actions
88 lines (84 loc) · 1.95 KB
/
gesturedetector.cpp
File metadata and controls
88 lines (84 loc) · 1.95 KB
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
77
78
79
80
81
82
83
84
85
86
87
88
#include "gesturedetector.h"
#include <QDebug>
#define TIME_TO_RESET 20
GestureDetector::GestureDetector()
{
critDeltaWidth = 60;
critHeight = 30;
prevWidth = INT_MAX;
accumulator = Accumulator();
chilloutcounter = 0;
minDisp = 100.0F;
minWidthRate = 0.05F;
}
bool GestureDetector::detect(cv::Mat& frame)
{
if (chilloutcounter!=0)
{
chilloutcounter++;
if (chilloutcounter == TIME_TO_RESET)
{
qDebug()<<"chilout ended";
chilloutcounter = 0;
}
return false;
}
int currentHorWhite = 0;
int MaxHorWhite = 0;
for (int x = 0; x < frame.cols; ++x)
{
int maxWhite = 0;
int currentWhite = 0;
for (int y = 0; y < frame.rows; ++y)
{
if (frame.at<uchar>(y,x) > 0)
{
currentWhite++;
}
else
{
if (maxWhite<currentWhite)
{
maxWhite = currentWhite;
}
currentWhite = 0;
}
}
if (maxWhite > critHeight)
{
currentHorWhite++;
}
else
{
if (MaxHorWhite<currentHorWhite)
{
MaxHorWhite = currentHorWhite;
}
currentHorWhite = 0;
}
}
prevWidth = MaxHorWhite;
if (accumulator.accumulate(MaxHorWhite))
{
// gesture detected
if (frame.size().width * minWidthRate > MaxHorWhite)
{
// too short body width
accumulator.forceLearn();
return false;
}
if (accumulator.getDisp() < minDisp)
{
// too little disp accumulated, don't make such unconsidered decisions
accumulator.forceLearn();
return false;
}
chilloutcounter++;
accumulator.reset();
return true;
}
else
{
return false;
}
}