Skip to main content

Camera feed into a VLM

Time: 9:55 AM to 10:55 AM
Now you will connect the robot’s camera directly to a vision language model. The robot captures what it sees, sends the image to GPT-4o-mini, and describes it — either on screen or aloud.

The architecture


Program 1: Test the vision API

Start simple — capture one photo, send it to GPT, and print what it sees.

Step 1 — Capture a frame as base64

The picamera2 library captures JPEG frames. Convert to base64 so it can be included in the API request:
The image becomes a long text string (about 50-80 KB) that gets embedded directly in the API request.

Step 2 — Send image + text to the vision API

The key difference from Day 3: the content field is now a list containing both text and image data:
Notice the content field changed from a simple string to a list with two items: the text prompt and the image. The detail: "low" setting keeps token costs down.

Step 3 — Interactive loop

After the first description, let the user ask follow-up questions about the same image or snap a new one:

Run it

Point the camera at different objects and see what GPT describes:
Try these experiments:
  • Hold up different colored objects and ask “what color is this?”
  • Show it text on a piece of paper and ask “what does this say?”
  • Point it at a person and ask “describe who you see”
  • Cover the lens and ask “what do you see?” — the model will say it is dark

Program 2: Vision chatbot

Now add voice and TTS. The robot captures a photo with every question, sends both the image and your spoken question to GPT, and speaks the answer.

Step 1 — Combine camera + voice input

The key difference from Day 3’s voice chatbot: every API call now includes a fresh camera frame alongside the text:

Step 2 — The conversation loop with camera

Every iteration: listen → capture photo → send both to GPT → speak response:
The robot always sends a current photo, so if you move an object between questions, the model sees the change.

Run it

Or keyboard mode:
Try these interactions:
After this section, take a 10-minute break (10:55 AM to 11:05 AM).