-
Notifications
You must be signed in to change notification settings - Fork 1
/
test1.py
66 lines (51 loc) · 2.28 KB
/
test1.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
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
from PIL import Image
import numpy as np
import anki_vector
from anki_vector.events import Events
from anki_vector.util import degrees
import time
from keras.applications.xception import Xception
from keras.preprocessing import image
from keras.applications.xception import preprocess_input, decode_predictions
model = Xception(weights='imagenet')
screen_dimensions = anki_vector.screen.SCREEN_WIDTH, anki_vector.screen.SCREEN_HEIGHT
with anki_vector.Robot() as robot:
# If necessary, move Vector's Head and Lift down
screen_dimensions = anki_vector.screen.SCREEN_WIDTH, anki_vector.screen.SCREEN_HEIGHT
while True:
robot.behavior.set_lift_height(0.0)
robot.behavior.set_head_angle(degrees(0.0))
robot.camera.init_camera_feed()
robot.vision.enable_display_camera_feed_on_face(True)
robot.camera.latest_image.raw_image.save('./latest.jpg', 'JPEG')
robot.camera.close_camera_feed()
oimage = Image.open('./latest.jpg')
print("Display image on Vector's face...")
screen_data = anki_vector.screen.convert_image_to_screen_data(oimage.resize(screen_dimensions))
robot.screen.set_screen_with_image_data(screen_data, 5.0, True)
oimage = oimage.crop(box=(170,0,469,299))
x = image.img_to_array(oimage)
x = np.expand_dims(x, axis=0)
x = preprocess_input(x)
preds = model.predict(x)
word = decode_predictions(preds, top=1)
for i in (word):
for j in i:
obj = j[1]
obj = obj.replace("_"," ")
print('Predicted:', obj)
if obj == "pill bottle":
robot.behavior.say_text('I need to take my meds!')
robot.anim.play_animation_trigger('GreetAfterLongTime')
else:
robot.behavior.say_text('Might be {}'.format(obj))
robot.vision.enable_display_camera_feed_on_face(False)
battery_state = robot.get_battery_state()
print(f"battery state: {battery_state}")
if battery_state.battery_volts <= 3.6:
robot.behavior.say_text('I too hungry to work')
robot.behavior.drive_on_charger()
break
robot.disconnect()
time.sleep(30)
robot.connect()