Skip to main content
LeRobot provides unified camera interfaces for capturing images during robot operation, data collection, and policy execution. The framework supports multiple camera backends including OpenCV (webcams, USB cameras) and Intel RealSense (depth cameras).

Supported Camera Types

OpenCV Cameras

OpenCV cameras work with any device supported by OpenCV’s VideoCapture, including:
  • USB webcams
  • Laptop built-in cameras
  • Industrial cameras with V4L2 support (Linux)
  • Video files for testing

Intel RealSense Cameras

RealSense cameras provide both color and depth sensing:
  • D400 series (D405, D415, D435, D455)
  • SR300 series
  • L500 series

Installation

OpenCV Camera Dependencies

OpenCV support is included by default with LeRobot:

RealSense Camera Dependencies

For Intel RealSense cameras, install additional dependencies:

Finding Cameras

Use the built-in camera discovery tools to identify connected cameras:

Find OpenCV Cameras

Example output:

Find RealSense Cameras

Example output:

Configuration

OpenCV Camera Configuration

Configuration Parameters:
  • index_or_path: Camera index (e.g., 0, 1) or device path (e.g., /dev/video4)
  • fps: Frames per second (default: None, uses camera default)
  • width, height: Resolution in pixels (default: None, uses camera default)
  • color_mode: ColorMode.RGB or ColorMode.BGR (default: RGB)
  • rotation: NO_ROTATION, ROTATE_90_CLOCKWISE, ROTATE_90_COUNTERCLOCKWISE, ROTATE_180
  • fourcc: Video format code (e.g., “MJPG”, “YUYV”, “H264”)
  • warmup_s: Warmup time in seconds before first frame (default: 1)
From /home/daytona/workspace/source/src/lerobot/cameras/opencv/configuration_opencv.py:23

RealSense Camera Configuration

Configuration Parameters:
  • serial_number_or_name: Unique serial number or camera name
  • fps, width, height: Must all be set or all be None (uses camera defaults)
  • use_depth: Enable depth stream (default: False)
  • color_mode: ColorMode.RGB or ColorMode.BGR (default: RGB)
  • rotation: Same options as OpenCV
  • warmup_s: Warmup time in seconds (default: 1)
From /home/daytona/workspace/source/src/lerobot/cameras/realsense/configuration_realsense.py:22

Basic Usage

Connecting to a Camera

Reading Frames

LeRobot cameras support three frame reading methods:

1. Synchronous Read (Blocking)

Waits for the next frame from the camera:

2. Asynchronous Read (Background Thread)

Reads from a background thread with timeout:

3. Read Latest (Non-blocking)

Returns the most recent frame immediately:
From /home/daytona/workspace/source/src/lerobot/cameras/opencv/camera_opencv.py:351

Reading Depth (RealSense Only)

From /home/daytona/workspace/source/src/lerobot/cameras/realsense/camera_realsense.py:322

Disconnecting

Advanced Usage

Multi-Camera Setup

High-Speed Capture with MJPEG

For higher frame rates, use Motion JPEG format:

Continuous Capture Loop

Color Space Conversion

Camera Calibration

For robot applications requiring precise camera calibration:

Linux-Specific Tips

Camera Permissions

Add your user to the video group:

Checking Camera Capabilities

Stable Camera Paths with udev

Create a udev rule for consistent device paths:
Then use /dev/camera-front instead of /dev/video0.

Troubleshooting

OpenCV Issues

Camera not found:
  • Run lerobot-find-cameras opencv to list available cameras
  • Check camera is not in use by another application
  • Try different camera indices (0, 1, 2, …)
  • On Linux, check /dev/video* permissions
Low frame rate:
  • Try different fourcc formats (“MJPG” often faster than “YUYV”)
  • Reduce resolution
  • Check USB bandwidth (use USB 3.0 ports)
  • Close other applications using the camera
Wrong colors:
  • Check color_mode setting (RGB vs BGR)
  • Some cameras may need specific fourcc settings

RealSense Issues

“No RealSense devices detected”:
  • Check USB connection (use USB 3.0 ports for best performance)
  • Verify pyrealsense2 is installed: pip install pyrealsense2
  • On Linux, check udev rules are installed: sudo apt install librealsense2-dkms
  • Run lerobot-find-cameras realsense to verify detection
Firmware version errors: Depth stream issues:
  • Ensure use_depth=True in configuration
  • Check that depth is supported at your resolution/FPS combination
  • Try lower resolution or frame rate
  • Depth sensing requires adequate lighting and non-reflective surfaces

Performance Tips

  1. Use MJPEG format for higher frame rates with USB cameras
  2. Reduce resolution if you don’t need high detail
  3. Use async_read() in high-frequency control loops
  4. Disable warmup for faster connection: warmup_s=0 (may cause initial frame drops)
  5. Use background threads for multi-camera setups
  6. On Windows, set OPENCV_VIDEOIO_MSMF_ENABLE_HW_TRANSFORMS=0 (done automatically)

References