ALVisionToolbox Tutorial

Overview | API | Tutorial

Introduction

This tutorial explains how to run the ALVisionToolbox functions using Python.

Getting a proxy to ALVisionToolbox

After some initialization steps, we first instantiate a proxy to the ALVisionToolbox module.

# This test demonstrates how to use the ALVisionToolbox module.
# Note that you might not have this module depending on your distribution
import os
import sys
import time
from naoqi import ALProxy

# Replace this with your robot's IP address
IP = "10.0.252.91"
PORT = 9559

# Create a proxy to ALVisionToolbox
try:
  visionToolboxProxy = ALProxy("ALVisionToolbox", IP, PORT)
except Exception, e:
  print "Error when creating vision toolbox proxy:"
  print str(e)
  exit(1)

Asking if it is dark

result = visionToolboxProxy.isItDark()
if result > 210:
  print "It's time to sleep"
else:
  print "I might not go to bed at such an hour"

Asking if there is backlighting

result = visionToolboxProxy.backlighting()
if result > 2:
  print "I can't hardly see with this light"
elif result > 1:
  print "This light might be slightly disturbing"

Taking pictures

visionToolboxProxy.takePicture()
print "ok, you can move now"

Taking pictures regularly

# For launching the regular image acquisitions
visionToolboxProxy.takePictureRegularly(0.5, "lastImage", True, "jpg", 0)
print "Tracking of NAO's view activated."

# for launching it in a non blocking way
visionToolboxProxy.post.takePictureRegularly(0.5, "lastImage", True, "jpg", 0)
print "Tracking of NAO's view activated."
visionToolboxProxy.post.takePictureRegularly(60, "img", False, "jpg", 0)
print "History of what NAO will see today"

time.sleep(5)

# For stopping the second one
visionToolboxProxy.stopTPR("img", "jpg")
print "Stop the history"

Record a video file

# We'll save a 5 second video record in /home/nao/naoqi/share/naoqi/vision
visionToolboxProxy.startVideoRecord("test.avi")
print "Video record started."

time.sleep(5)

videoInfo = visionToolboxProxy.stopVideoRecord()
print "Video was saved on the robot: ", videoInfo[1]
print "Num frames: ", videoInfo[0]

Set white balance

# parameters: 0 top camera - 1 bottom camera - 2 both
visionToolboxProxy.setWhiteBalance(1)
print "Born to be alive! ;-)"