-
-
Notifications
You must be signed in to change notification settings - Fork 60
/
video.py
executable file
·50 lines (35 loc) · 1.33 KB
/
video.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
#!/usr/bin/env python
from PIL import Image
import pycozmo
# Last image, received from the robot.
last_im = None
def on_camera_image(cli, new_im):
""" Handle new images, coming from the robot. """
global last_im
last_im = new_im
with pycozmo.connect(enable_procedural_face=False) as cli:
# Raise head.
angle = (pycozmo.robot.MAX_HEAD_ANGLE.radians - pycozmo.robot.MIN_HEAD_ANGLE.radians) / 2.0
cli.set_head_angle(angle)
# Register to receive new camera images.
cli.add_handler(pycozmo.event.EvtNewRawCameraImage, on_camera_image)
# Enable camera.
cli.enable_camera()
# Run with 14 FPS. This is the frame rate of the robot camera.
timer = pycozmo.util.FPSTimer(14)
while True:
if last_im:
# Get last image.
im = last_im
# Resize from 320x240 to 68x17. Larger image sometime are too big for the robot receive buffer.
im = im.resize((68, 17))
# Convert to binary image.
im = im.convert('1')
# Mirror the image.
im = im.transpose(Image.FLIP_LEFT_RIGHT)
# Construct a 128x32 image that the robot can display.
im2 = Image.new("1", (128, 32))
im2.paste(im, (30, 7))
# Display the result image.
cli.display_image(im2)
timer.sleep()