Skip to content

Capture from a Webcam

Hadware Communication

This tutorial walks you through how to use medulla to capture an image from a USB webcam and visualize it in Rerun.

Hardware required

You need a USB webcam connected to your machine. A built-in laptop camera works too - camera_id=0 selects the default camera.

Run the Capture from Webcam using Medulla

Save the script

Create a file called quickstart_webcam_example.py anywhere on your machine and paste the following

python
"""Telekinesis quickstart: capture a single frame from a USB webcam.

Connects to the default webcam, captures one color frame, and visualizes
it in a Rerun viewer.

Run as a script - python quickstart_webcam_example.py
"""

import rerun as rr
from loguru import logger

from telekinesis.medulla.cameras import webcam


def main() -> None:
    # Opens the Rerun viewer (spawn=True).
    rr.init("telekinesis_medulla_quickstart", spawn=True)
    
    # camera_id=0 is usually the default laptop camera or first USB webcam.
    camera = webcam.Webcam(name="my_webcam_camera", camera_id=0)

    try:
        camera.connect()
        # Skill call: Capture one color image as an HWC uint8 NumPy array.
        image = camera.capture_color_image()
        height, width = image.shape[:2]
        logger.success(f"Captured a {width}x{height} frame")
        
        # Log under entity path "webcam" so it appears in the spatial view.
        rr.log("webcam", rr.Image(image))
    except Exception as exc:
        logger.error(f"Failed to capture frame: {exc!r}")
    finally:
        camera.disconnect()


if __name__ == "__main__":
    main()

Run the script!

bash
python quickstart_webcam_example.py
Webcam capture output visualized in Rerun
Captured frame visualized in Rerun.
Free TierEvery new account starts on a free tier with credits to call the SDK — no billing details required.Create API key →

Where to Go Next?

Ready to go deeper? Browse the Telekinesis Skill Examples repository for a runnable example covering every Skill.

Skill Skill Examples
One runnable example per Skill, across vision, 3D, hardware, and robotics.

Explore the Docs

Support