Skip to content

Advanced

Camera Connector

Simulates image capture from a camera and publishes the image in base64 format to the Kelvin Platform.

In production environments, it would interface directly with live camera feeds to acquire real-time images.

Code

The full code is hosted in the Kelvin App Samples repository on GitHub here.

Repository contents

  • .dockerignore — docker ignore rules (present in repo).
  • Dockerfile — container image build file (present).
  • README.md — repository README for this folder (present).
  • app.yaml — app descriptor for deployment to the Kelvin platform (present).
  • images/ — directory intended to hold images to be published (empty dir placeholder included).
  • main.py — main Python script that performs the image reading, base64 conversion, and publishing.
  • requirements.txt — Python dependencies list.

Basic Code Explanation

The main.py script continuously reads image files from a folder, converts them to base64, and streams them to the Kelvin platform as data messages.

It connects to the Kelvin platform through KelvinApp, uses Pillow to open and process each image, and packages the image bytes, format, and size into a structured dictionary.

Each dictionary is serialized to JSON and published as a KMessageTypeData message on the "camera-feed" datastream for every configured asset in the app.

At runtime, the script runs an endless loop that scans the images/ directory, converts available images into base64 payloads, and sends them every 30 seconds.

The generator function handles all image encoding and gracefully skips unreadable files.

This allows any connected Kelvin asset to receive regular image data updates in a consistent JSON format, supporting image streaming, storage, or AI-based image processing within the Kelvin ecosystem.