Display Image on Cozmo Face OLED Display

Want to know how to display an image on Cozmo’s face OLED display? We’ve got you covered. We will show you how to display an image of the Kinvert logo on Cozmo’s face using the OLED display using several commands including cozmo.oled_face.convert_image_to_screen_data.

For all things Cozmo related, check out Anki Cozmo SDK Programmable Robot for Kids.

Cozmo face OLED display image convert_image_to_screen_data Kinvert Cozmo tutorial example project

Display Image on Cozmo Face OLED Display

If you recall from our central article on Cozmo Face OLED Display, we need to convert everything to screen data.

Remember, when doing a search we find several tools:

  • cozmo.oled_face
  • cozmo.robot.Robot.display_oled_face_image_factory
  • cozmo.oled_face.convert_image_to_screen_data
  • cozmo.oled_face.convert_pixels_to_screen_data
  • cozmo.oled_face.dimensions

Which do you think we should use? If you’re a Kinvert student I want you to stop and think about that before moving on. Obviously if this was one of our Courses, in person or virtual, the answer wouldn’t be right in front of you. We have a higher standard than that. So please no peeking below 🙂

Well since we’re working with images, it seems like we’ll want to use convert_image_to_screen_data. Let’s take a closer look at that.

cozmo.oled_face.convert_image_to_screen_data

The big things we’re interested are the parameters and returns. In this case the convert_image_to_screen_data() function requests the pixel_data in bytes. This must be a fully binary image consisting of only zeros 0’s and ones 1’s. They also have image_width and image_height as parameters. As expected, these are integer values.

What does cozmo.oled_face.convert_image_to_screen_data() return? A bytearray. Hacking in to specifically what that means is beyond the scope of this post. Just keep in mind that this is the screen data the droid is looking for.

http://cozmosdk.anki.com/docs/generated/cozmo.oled_face.html?#cozmo.oled_face.convert_image_to_screen_data

The Code

NOTE – To make this code work you must download and save this image in the same exact folder as your code. Otherwise the program will freak out when it can’t find the image file itself.

Please let me know if this image doesn’t work after downloading. It’s possible in some browsers the image won’t be downloaded as a true binary image file.

cozmo face oled display an image on cozmo's face OLED display using Python sdk

Please forgive me while we work on finding a better way to display code on our site:


"""
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 cozmo
import time
try:
    from PIL import Image
except:
    print("Looks like you need to install Pillow")

def kinvert_face(robot: cozmo.robot.Robot):
        
    image = Image.open("kinvert.png")
    image = image.resize(cozmo.oled_face.dimensions(), Image.NEAREST)
    image = cozmo.oled_face.convert_image_to_screen_data(image)

    seconds = 10

    for nothing in range(seconds):
        robot.display_oled_face_image(image, 1000.0)
        time.sleep(1.0)

cozmo.robot.Robot.drive_off_charger_on_connect = False
cozmo.run_program(kinvert_face)

To learn more about Kinvert’s Robotics Classes for Kids and Teens.

If you’re an educator you might want to check out our article on Anki Cozmo STEM Curriculum for K-12.

Cozmo Examples, Tutorials, and Projects for K-12 STEM Education Curriculum

Looking for robotics projects that don’t involve Cozmo? Check out our Ultimate Guide to Robotics Projects and Ideas.

You can also do this with the Anki Vector SDK and Anki Vector Coding Examples.

If Python seems a bit tough, check out Age to Teach Kids Python, Block Coding, and What is Robotics?

Leave a Reply

Your email address will not be published. Required fields are marked *