RealSense: Stream Point Cloud
SUMMARY
Connect to a RealSense camera, configure resolution and frame rate, stream a colour-mapped point cloud continuously for 10 seconds, and visualise the live 3D feed with Rerun.
Example
Code
"""
A simple example demonstrating how to connect to a RealSense camera, stream a
colour-mapped point cloud and disconnect from the camera when finished.
Please run this example 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_Pointcloud_Video_Example", spawn=True)
rr.log("/", rr.ViewCoordinates.RDF, static=True)
camera.connect(
width=640,
height=480,
fps=30,
)
end_time = time.time() + 10
while time.time() < end_time:
point_cloud = camera.capture_video_pointcloud()
if point_cloud is None:
continue
rr.log(
"Continuous_Pointcloud_Capture",
rr.Points3D(positions=point_cloud.positions, colors=point_cloud.colors),
)
except Exception as e:
logger.error(
f"Unable to stream point cloud. Caught exception: {type(e).__name__}: {e}"
)
finally:
camera.disconnect()
if __name__ == "__main__":
main()Explanation
Now, let's break down the code piece by piece.
The camera object is created with just a name. Unlike the IDS camera, no serial number or factory-defaults flag is required — the RealSense class connects to the first available device by default.
camera = realsense.RealSense(
name="my_realsense",
)Before connecting, the Rerun viewer is opened and a world coordinate frame is set. rr.ViewCoordinates.RDF declares Right-Down-Forward axes for the scene — a convention that matches the RealSense depth sensor's native orientation and ensures Rerun renders the point cloud the right way up. Passing static=True logs this once rather than repeating it on every frame.
rr.init("RealSense_Pointcloud_Video_Example", spawn=True)
rr.log("/", rr.ViewCoordinates.RDF, static=True)Stream configuration is passed directly to connect rather than set via parameters after the fact. width, height, and fps control both the colour and depth streams simultaneously, so both are aligned and ready from the first frame.
camera.connect(
width=640,
height=480,
fps=30,
)The streaming loop runs for 10 seconds using a wall-clock deadline rather than a fixed frame counter. Each call to capture_video_pointcloud returns a point-cloud object with a .positions attribute (an Nx3 float array of XYZ coordinates) and a .colors attribute (an Nx3 uint8 array of RGB values per point), or None if no frame is ready yet. The None check skips logging until a valid frame arrives rather than crashing.
end_time = time.time() + 10
while time.time() < end_time:
point_cloud = camera.capture_video_pointcloud()
if point_cloud is None:
continueUnlike the 2D video examples, no JPEG encoding step is needed — the data is already numeric arrays. rr.Points3D accepts positions and per-point colours directly, sending the full coloured cloud to Rerun in a single log call.
rr.log(
"Continuous_Pointcloud_Capture",
rr.Points3D(positions=point_cloud.positions, colors=point_cloud.colors),
)The finally block disconnects the camera, stopping the RealSense pipeline and releasing all USB resources regardless of whether an exception occurred.
finally:
camera.disconnect()Run
python realsense_pointcloud_example.pyA Rerun viewer opens automatically. The 3D point cloud streams under Continuous_Pointcloud_Capture for 10 seconds, then the camera disconnects cleanly.

