forked from cltl/pepper
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathobjects.py
More file actions
59 lines (39 loc) · 1.99 KB
/
objects.py
File metadata and controls
59 lines (39 loc) · 1.99 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
"""Example Application that tells you what it sees"""
from pepper.framework import * # Application Building Blocks
from pepper import config # Global Configuration File
from time import time
class ObjectApplication(AbstractApplication, # Each Application inherits from AbstractApplication
ObjectDetectionComponent, # Object Detection Component (using pepper_tensorflow)
TextToSpeechComponent): # Text to Speech, for Speaking using the self.say method
OBJECT_TIMEOUT = 15
def __init__(self, backend):
# Initialize Superclasses (very, very important)
super(ObjectApplication, self).__init__(backend)
# Keep track of which objects are seen when
self.object_time = {}
def on_object(self, objects):
"""
On Object Event.
Called every time one or more objects are detected in a camera frame.
"""
# For each object in camera frame,
for obj in objects:
# Check whether speaking is appropriate
if self.is_object_recognition_appropriate(obj.name):
# Then tell human what you saw
self.say("I see a {}".format(obj.name))
def is_object_recognition_appropriate(self, name):
"""Returns True if telling about objects is appropriate and updates Object Time"""
# Appropriateness arises when
# 1. object hasn't been seen before, or
# 2. enough time has passed since last sighting
if name not in self.object_time or (time() - self.object_time[name] > self.OBJECT_TIMEOUT):
# Store last seen time (right now) in object_time dictionary
self.object_time[name] = time()
# Return "Appropriate"
return True
# Return "Not Appropriate"
return False
if __name__ == "__main__":
# Run ObjectApplication using Backend Configured in Global Configuration File
ObjectApplication(config.get_backend()).run()