Skip to content

Stream Live Depth Video

SUMMARY

Stream Live Depth Video acquires continuous depth frames in a loop, returning each frame as a NumPy array of float values in metres. Pair with a Rerun DepthImage colour map for a live false-colour visualisation of distance over time.

Available on: Intel RealSense.

The Skill

python
depth_image = camera.capture_video_depth_frame()

Call repeatedly inside a loop. The depth stream stays running continuously between calls.

Example

The Code

python
"""
Stream live depth video from a RealSense camera with a turbo colour map.

Run from a terminal to avoid issues with Rerun's spawn mode.
"""
import time
from loguru import logger

import rerun as rr

from telekinesis.medulla.cameras import realsense


def main():
    camera = realsense.RealSense(name="my_realsense")
    try:
        rr.init("RealSense_Video_Example", spawn=True)
        camera.connect()

        end_time = time.time() + 10
        while time.time() < end_time:
            depth_image = camera.capture_video_depth_frame()
            rr.log(
                "Continuous_Depth_Image_Capture",
                rr.DepthImage(
                    depth_image,
                    meter=1.0,                # values are already in metres
                    colormap="turbo",
                    depth_range=(0.0, 3.0),   # 0–3 metres
                ),
            )
    except Exception as e:
        logger.error(f"Unable to stream video. {type(e).__name__}: {e}")
    finally:
        camera.disconnect()


if __name__ == "__main__":
    main()

The Explanation of the Code

The streaming loop runs for 10 seconds using a wall-clock deadline rather than a fixed frame counter. Each call to capture_video_depth_frame keeps the depth stream running continuously between calls and returns one frame as a NumPy array of float values already in metres. Unlike the colour video example, no None guard is needed here — the depth stream always returns a valid frame once the pipeline is running.

Each frame is logged as a rr.DepthImage with the same display settings on every iteration:

  • meter=1.0 tells Rerun the values are already in metres.
  • colormap="turbo" maps close distances to blue and far distances to red.
  • depth_range=(0.0, 3.0) clamps the colour scale to the 0–3 metre range.
python
end_time = time.time() + 10
while time.time() < end_time:
    depth_image = camera.capture_video_depth_frame()
    rr.log(
        "Continuous_Depth_Image_Capture",
        rr.DepthImage(depth_image, meter=1.0, colormap="turbo", depth_range=(0.0, 3.0)),
    )

The disconnect call lives in a finally block so the RealSense pipeline and USB resources are released regardless of how the loop exits.

Running the Example

bash
python capture_depth_video_example.py

A Rerun viewer opens automatically. Depth frames stream under Continuous_Depth_Image_Capture for 10 seconds with the turbo colour map applied, then the camera disconnects cleanly.

Where to Use the Skill

  • Live distance monitoring — observe how depth changes as the scene or robot moves.
  • Calibration sanity checks — verify the depth pipeline is producing valid frames continuously.
  • Mixed-mode pipelines — combine with stream_live_color_video when both colour and depth feeds are needed.