Skip to content

Commit d9e014b

Browse files
author
cwlroda
committed
Added 2D-plane vector calculations in fall detection algorithm
1 parent 2b0e64a commit d9e014b

File tree

43 files changed

+35
-22
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+35
-22
lines changed

core/falldetector.py

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1+
import math
12
import logging
23
from collections import OrderedDict
4+
from queue import Queue
35

46
LOG = logging.getLogger(__name__)
57

@@ -11,31 +13,31 @@ def __init__(self):
1113
def update(self, persons, framecount, fps):
1214
self.falls = OrderedDict()
1315

14-
for ID, (x, y, x_, y_, w_, h_, l_knee, r_knee) in persons.items():
16+
for ID, (x, y, x_, y_, w_, h_) in persons.items():
1517
if framecount == 0:
16-
self.old_persons[ID] = (x, y, h_, False)
18+
self.old_persons[ID] = (x, y, w_, h_, False)
1719

1820
else:
1921
if ID in self.old_persons:
20-
(old_x, old_y, old_h, fall) = self.old_persons[ID]
21-
22-
if w_ >= h_:
23-
if (l_knee != 0 or r_knee != 0) and y-old_y >= old_h/2:
22+
(old_x, old_y, old_w, old_h, fall) = self.old_persons[ID]
23+
24+
if w_ >= 1.2*h_:
25+
if math.sqrt(pow(abs(x-old_x), 2)+pow((y-old_y), 2)) >= 0.7*math.sqrt(pow(old_w, 2)+pow(old_h, 2)):
2426
LOG.info("FALL DETECTED")
2527
self.falls[ID] = (x_, y_, w_, h_)
26-
self.old_persons[ID] = (x, y, old_h, True)
28+
self.old_persons[ID] = (x, y, old_w, old_h, True)
2729

2830
elif fall:
2931
self.falls[ID] = (x_, y_, w_, h_)
3032

31-
elif framecount % round(fps) == 0:
32-
self.old_persons[ID] = (x, y, h_, False)
33+
elif framecount % int(fps) == 0:
34+
self.old_persons[ID] = (x, y, w_, h_, False)
3335

3436
else:
35-
self.old_persons[ID] = (old_x, old_y, old_h, False)
37+
self.old_persons[ID] = (old_x, old_y, old_w, old_h, False)
3638

3739
else:
38-
self.old_persons[ID] = (x, y, h_, False)
40+
self.old_persons[ID] = (x, y, w_, h_, False)
3941

4042
return self.falls
4143

core/tracker.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,10 @@
77

88

99
class CentroidTracker():
10-
def __init__(self, frame_threshold=30):
10+
def __init__(self):
1111
self.ID = 0
1212
self.objects = OrderedDict()
1313
self.disappeared = OrderedDict()
14-
self.frame_threshold = frame_threshold
1514

1615
def register(self, centroid):
1716
self.objects[self.ID] = centroid
@@ -22,12 +21,12 @@ def deregister(self, ID):
2221
del self.objects[ID]
2322
del self.disappeared[ID]
2423

25-
def update(self, inputCentroids):
24+
def update(self, inputCentroids, frame_threshold):
2625
if len(inputCentroids) == 0:
2726
for ID in list(self.disappeared.keys()):
2827
self.disappeared[ID] += 1
2928

30-
if self.disappeared[ID] > self.frame_threshold:
29+
if self.disappeared[ID] > 2*frame_threshold:
3130
self.deregister(ID)
3231

3332
return self.objects
@@ -66,7 +65,7 @@ def update(self, inputCentroids):
6665
ID = IDs[row]
6766
self.disappeared[ID] += 1
6867

69-
if self.disappeared[ID] > self.frame_threshold:
68+
if self.disappeared[ID] > 2*frame_threshold:
7069
self.deregister(ID)
7170

7271
else:
-48.8 KB
Binary file not shown.
-49.7 KB
Binary file not shown.
-51.2 KB
Binary file not shown.
-53.2 KB
Binary file not shown.
-51.8 KB
Binary file not shown.
-49.7 KB
Binary file not shown.
-48.1 KB
Binary file not shown.
-51.2 KB
Binary file not shown.

0 commit comments

Comments
 (0)