anki_vector.camera

Support for Vector’s camera.

Vector has a built-in camera which he uses to observe the world around him.

The CameraComponent class defined in this module is made available as anki_vector.robot.Robot.camera and can be used to enable/disable image sending and observe images being sent by the robot. It emits EvtNewRawCameraImage and EvtNewCameraImage objects whenever a new camera image is available.

The camera resolution is 1280 x 720 with a field of view of 90 deg (H) x 50 deg (V).

Classes

CameraComponent(robot)

Represents Vector’s camera.

CameraImage(raw_image, image_annotator, image_id)

A single image from the robot’s camera.

EvtNewCameraImage(image)

Dispatched when a new camera image is received and processed from the robot’s camera.

EvtNewRawCameraImage(image)

Dispatched when a new raw image is received from the robot’s camera.

class anki_vector.camera.EvtNewRawCameraImage(image)

Dispatched when a new raw image is received from the robot’s camera.

See also EvtNewCameraImage which provides access to both the raw image and a scaled and annotated version.

import threading

import anki_vector
from anki_vector import events

def on_new_raw_camera_image(robot, event_type, event, done):
    print("Display new camera image")
    event.image.show()
    done.set()

with anki_vector.Robot() as robot:
    robot.camera.init_camera_feed()
    done = threading.Event()
    robot.events.subscribe(on_new_raw_camera_image, events.Events.new_raw_camera_image, done)

    print("------ waiting for camera events, press ctrl+c to exit early ------")

    try:
        if not done.wait(timeout=5):
            print("------ Did not receive a new camera image! ------")
    except KeyboardInterrupt:
        pass
Parameters

image (Image) – A raw camera image.

class anki_vector.camera.EvtNewCameraImage(image)

Dispatched when a new camera image is received and processed from the robot’s camera.

import threading

import anki_vector
from anki_vector import events

def on_new_camera_image(robot, event_type, event, done):
    print(f"Display new annotated camera image with id {event.image.image_id}")
    annotated_image = event.image.annotate_image()
    annotated_image.show()
    done.set()

with anki_vector.Robot(enable_face_detection=True, enable_custom_object_detection=True) as robot:
    robot.camera.init_camera_feed()
    done = threading.Event()
    robot.events.subscribe(on_new_camera_image, events.Events.new_camera_image, done)

    print("------ waiting for camera events, press ctrl+c to exit early ------")

    try:
        if not done.wait(timeout=5):
            print("------ Did not receive a new camera image! ------")
    except KeyboardInterrupt:
        pass
Param

A wrapped camera image object that contains the raw image.

class anki_vector.camera.CameraComponent(robot)

Represents Vector’s camera.

The CameraComponent object receives images from Vector’s camera, unpacks the data, composes it and makes it available as latest_image.

The anki_vector.robot.Robot or anki_vector.robot.AsyncRobot instance observes the camera.

import anki_vector

with anki_vector.Robot() as robot:
    robot.camera.init_camera_feed()
    image = robot.camera.latest_image
    image.raw_image.show()
Parameters

robot – A reference to the owner Robot object.

annotator_factory

alias of anki_vector.annotate.ImageAnnotator

capture_single_image()

Request to capture a single image from the robot’s camera.

This call requests the robot to capture an image and returns the received image, formatted as a Pillow image. This differs from latest_image, which maintains the last image received from the camera feed (if enabled).

Note that when the camera feed is enabled this call returns the latest_image.

import anki_vector

with anki_vector.Robot() as robot:
    image = robot.camera.capture_single_image()
    image.raw_image.show()
Return type

CameraImage

close_camera_feed()

Cancel camera feed task.

Return type

None

image_annotator

The image annotator used to add annotations to the raw camera images.

import time
import anki_vector

with anki_vector.Robot(show_viewer=True) as robot:
    # Annotations (enabled by default) are displayed on the camera feed
    time.sleep(5)
    # Disable all annotations
    robot.camera.image_annotator.annotation_enabled = False
    time.sleep(5)
Return type

ImageAnnotator

image_streaming_enabled()

True if image streaming is enabled on the robot

import anki_vector
with anki_vector.Robot() as robot:
    image_streaming_enabled = robot.camera.image_streaming_enabled()
    if image_streaming_enabled:
        print("Robot is streaming video")
    else:
        print("Robot is not streaming video")
Return type

bool

init_camera_feed()

Begin camera feed task.

import anki_vector

with anki_vector.Robot() as robot:
    robot.camera.init_camera_feed()
    image = robot.camera.latest_image
    image.raw_image.show()
Return type

None

latest_image

The most recently processed image received from the robot.

The resolution of latest_image is 640x360.

Getter

Returns the Pillow Image representing the latest image

import anki_vector

with anki_vector.Robot() as robot:
    robot.camera.init_camera_feed()
    image = robot.camera.latest_image
    image.raw_image.show()
Return type

CameraImage

Type

Image.Image

latest_image_id

The most recently processed image’s id received from the robot.

Used only to track chunks of the same image.

Getter

Returns the id for the latest image

import anki_vector

with anki_vector.Robot() as robot:
    robot.camera.init_camera_feed()
    image = robot.camera.latest_image
    image.raw_image.show()
    print(f"latest_image_id: {robot.camera.latest_image_id}")
Return type

int

class anki_vector.camera.CameraImage(raw_image, image_annotator, image_id)

A single image from the robot’s camera. This wraps a raw image and provides an annotate_image() method that can resize and add dynamic annotations to the image, such as marking up the location of objects and faces.

import anki_vector

with anki_vector.Robot() as robot:
    image = robot.camera.capture_single_image()
    print(f"Displaying image with id {image.image_id}, received at {image.image_recv_time}")
    image.raw_image.show()
Parameters
  • raw_image (Image) – The raw unprocessed image from the camera.

  • image_annotator (ImageAnnotator) – The image annotation object.

  • image_id (int) – An image number that increments on every new image received.

annotate_image(scale=None, fit_size=None, resample_mode=0)

Adds any enabled annotations to the image. Optionally resizes the image prior to annotations being applied. The aspect ratio of the resulting image always matches that of the raw image.

import anki_vector

with anki_vector.Robot() as robot:
    image = robot.camera.capture_single_image()
    annotated_image = image.annotate_image()
    annotated_image.show()
Parameters
  • scale (Optional[float]) – If set then the base image will be scaled by the supplied multiplier. Cannot be combined with fit_size

  • fit_size (Optional[tuple]) – If set, then scale the image to fit inside the supplied (width, height) dimensions. The original aspect ratio will be preserved. Cannot be combined with scale.

  • resample_mode (int) – The resampling mode to use when scaling the image. Should be either RESAMPLE_MODE_NEAREST (fast) or RESAMPLE_MODE_BILINEAR (slower, but smoother).

Return type

Image

image_id

An image number that increments on every new image received.

Return type

int

image_recv_time

The time the image was received and processed by the SDK.

Return type

float

raw_image

The raw unprocessed image from the camera.

Return type

Image