Loading...
「ツール」は右上に移動しました。
利用したサーバー: wtserver1
12いいね 1,325 views回再生

Vector reads a children's book

This video demonstrates (and for the first time in history also tries to give some quick insight, pardon my poor quality as one-man mobile phone videomaker) how to have Vector read a few lines from a children's book. For this experiment I used Julia Donaldson & Axel Scheffler's "Room on the broom", a fantastic book in rhyme. Hey BBC did also a CGI cartoon adaptation, check it out! :)

The demo uses Wirepod (https://github.com/kercre123/wire-pro...) installed on a Raspberry Pi4. You need also to install Tesseract which is very straightforward (https://www.macheronte.com/en/how-to-.... And of course I assume you must have installed Vector SDK and authenticated it with the robot.
My robot is a normal production Vector 1.0 running the wirepod OTA image. Sometimes you need to authenticate the SDK with the robot before putting him on wirepod.

The source code of the vision.py SDK script I am using:

#!/usr/bin/env python3

import shlex
import subprocess
import json
import threading
import time
import re

import anki_vector
from anki_vector import events

def doOCR():
tesseract = 'tesseract photo.jpg stdout'
args = shlex.split(tesseract)
process = subprocess.Popen(args, shell=False, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
stdout, stderr = process.communicate()
response = stdout.decode('utf-8')
response = response.strip()
response = re.sub(r'[^A-Za-z0-9 ]+', '', response)
print(response)
return response

with anki_vector.Robot(cache_animation_lists=False) as robot:
#robot.camera.init_camera_feed()
robot.motors.set_head_motor(-5.0)
time.sleep(1)
robot.motors.stop_all_motors()
image = robot.camera.capture_single_image()
annotated_image = image.annotate_image(None, (1280,720), anki_vector.annotate.RESAMPLE_MODE_NEAREST)
annotated_image.save("photo.jpg")
robot.motors.stop_all_motors()
txt = doOCR()
if len(txt) == 0:
txt = "I don't see anything"
robot.behavior.say_text(txt, False)

And about the runCmd.sh script I mentioned, it's simply something like this:

#!/bin/bash
cmd="/home/pi/vector-python-sdk/wirepod/$1.py \"${@:2}\""
echo $cmd
runuser -l pi -c "$cmd"

It just runs the script passed as a first parameter as system user "pi" and passes to the script the remaining command line parameters.

Happy coding!

コメント