-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathsceneanalyzer.py
36 lines (29 loc) · 986 Bytes
/
sceneanalyzer.py
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
from heartwave.person import Person
from eventkit import Op
class SceneAnalyzer(Op):
"""
Analyze heartrate for persons in a scene::
(frame, faces) -> (frame, persons)
"""
def __init__(self, source=None):
Op.__init__(self, source)
self.persons = []
def on_source(self, frame, faces):
present = set()
for face in faces:
x, y, w, h = face
cx = x + w / 2
cy = y + h / 2
person = next(
(p for p in self.persons if p.contains(cx, cy)), None)
if person:
person.setFace(face)
else:
person = Person(face)
self.persons.append(person)
present.add(person)
self.persons = [p for p in self.persons if p in present]
greenIm = frame.image[:, :, 1]
for person in self.persons:
person.analyze(frame.time, greenIm)
self.emit(frame, self.persons)