Kinvert helps you use Vector’s camera and display pictures on the screen using latest_image, convert_image_to_screen_data, set_screen_with_image_data.
Let’s Do More Than Just Display Images on Vector’s Face
If you have read our Anki Cozmo vs Vector Comparison you noticed a big difference between the two. Vector’s screen is full color while Cozmo’s is only blue.
We showed in Displaying an Image on Vector’s Face that displaying a color image is possible.
Now we will be showing you how to create a stream of images that displays every half second. These images are coming directly from Vector’s camera.
If you want to do something similar the Cozmo, check out the Cozmo SDK.
Time to start looking at the commands we will be using to take the camera feed and display it on Vector’s face screen.
Commands to Show Camera Image on Face
What commands will we be using? Here they are:
We will link out to the documentation when it is available. For now, check out this article Anki wrote about Keith Young and Kinvert: https://developer.anki.com/blog/features/interview/from-stem-to-learn/
Python Code to Display Camera Stream on Screen
Here we go. It’s time for the code.
This is very similar to our other examples. So be sure to check them out as well.
One difference here is we are enabling the camera feed by using enable_camera_feed=True. Without it Vector’s camera won’t be actively taking images.
I created this in a for loop so it won’t just go on forever.
Now this part is important though there are more than one ways to do it. We are saying while not robot.camera.latest_image:. I don’t want to explicitly tell you why, but rather ask you some questions after the code here.
We store the image with robot.camera.latest_image and resize it with image.resize((184,96)) so it will work with Vector’s IPS Display.
Finally we convert the image to screen data, and display it using anki_vector.screen.convert_image_to_screen_data() and robot.screen.set_screen_with_image_data().
""" Copyright Kinvert All Rights Reserved If you would like to use this code for business or education please contact us for permission at: www.kinvert.com/ """ import anki_vector import time from PIL import Image with anki_vector.Robot(enable_camera_feed=True) as robot: for _ in range(30): while not robot.camera.latest_image: time.sleep(1.0) image = robot.camera.latest_image image = image.resize((184,96)) screen_data = anki_vector.screen.convert_image_to_screen_data(image) robot.screen.set_screen_with_image_data(screen_data, 0.5) time.sleep(0.5)
What happens if you set enable_camera_feed to False?
What happens if you get rid of that while loop?
What is another way you can think of to deal with the problem of the camera delay in sending the first images?
What if we wanted a slower frame rate? How would we modify the code to make that happen?
This was a fun Anki Vector Example Using the SDK and we hope it was helpful. We used several things such as enable_camera_feed, latest_image, convert_image_to_screen_data(), and set_screen_with_image_data(). In the end we got Vector to show his camera stream on the IPS Display in his face.
Was this helpful? Did you make any modifications? Please share in the comments below.
Cozmo Examples, Tutorials, and Projects for STEM Education Curriculum is the place to go for Cozmo examples, in case you don’t have Vector yet. Also check out the Anki Cozmo SDK.