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.
We will be using the Anki Vector SDK for this article. This is one of many Kinvert Anki Vector Examples in Python. If you want to see more examples like this please check that article out.
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:
- robot.camera.latest_image
- image.resize
- anki_vector.screen.convert_image_to_screen_data()
- anki_vector.Robot.screen.set_screen_with_image_data()
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?
In Conclusion
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.
Contact Us For Help and Advice
If you’re interested in taking a Cozmo Camp Click Here or check out our Courses Page. We also use Cozmo in our Robotics Kids Class K-12.
How to set the Vector to show the latest photo it took with the command “take a photo” ?
I don’t think that’s supported in the SDK yet.
Does anyone know how to do this right now?
I would attempt to have the checking of a new photo occur in a separate thread and only consider displaying the image of a new photo has occured. A struct (from a c background) would be good to hold a number that updates each time a photo is taken, you can compare that with the current photo in the loop and if it current photo number is less than the threaded photo number then it must be a new image, this you can show it.
If I get a hold of Vector I will happily give this a go, (the above was a solution for a similar issue with a different robot).