LeRobot documentation

Cameras

Hugging Face's logo
Join the Hugging Face community

and get access to the augmented documentation experience

to get started

Cameras

LeRobot offers multiple options for video capture, including phone cameras, built-in laptop cameras, external webcams, and Intel RealSense cameras. To efficiently record frames from most cameras, you can use either the OpenCVCamera or RealSenseCamera class. For additional compatibility details on the OpenCVCamera class, refer to the Video I/O with OpenCV Overview.

Finding your camera

To instantiate a camera, you need a camera identifier. This identifier might change if you reboot your computer or re-plug your camera, a behavior mostly dependant on your operating system.

To find the camera indices of the cameras plugged into your system, run the following script:

python lerobot/find_cameras.py opencv # or realsense for Intel Realsense cameras

The output will look something like this if you have two cameras connected:

--- Detected Cameras ---
Camera #0:
  Name: OpenCV Camera @ 0
  Type: OpenCV
  Id: 0
  Backend api: AVFOUNDATION
  Default stream profile:
    Format: 16.0
    Width: 1920
    Height: 1080
    Fps: 15.0
--------------------
(more cameras ...)

When using Intel RealSense cameras in macOS, you could get this error: Error finding RealSense cameras: failed to set power state, this can be solved by running the same command with sudo permissions. Note that using RealSense cameras in macOS is unstable.

Use Cameras

Below are two examples, demonstrating how to work with the API.

  • Asynchronous frame capture using an OpenCV-based camera
  • Color and depth capture using an Intel RealSense camera
Open CV Camera
Intel Realsense Camera
from lerobot.common.cameras.opencv.configuration_opencv import OpenCVCameraConfig
from lerobot.common.cameras.opencv.camera_opencv import OpenCVCamera
from lerobot.common.cameras.configs import ColorMode, Cv2Rotation

# Construct an `OpenCVCameraConfig` with your desired FPS, resolution, color mode, and rotation.
config = OpenCVCameraConfig(
    index_or_path=0,
    fps=15,
    width=1920,
    height=1080,
    color_mode=ColorMode.RGB,
    rotation=Cv2Rotation.NO_ROTATION
)

# Instantiate and connect an `OpenCVCamera`, performing a warm-up read (default).
camera = OpenCVCamera(config)
camera.connect()

# Read frames asynchronously in a loop via `async_read(timeout_ms)`
try:
    for i in range(10):
        frame = camera.async_read(timeout_ms=200)
        print(f"Async frame {i} shape:", frame.shape)
finally:
    camera.disconnect()

Use your phone

Mac
Linux

To use your iPhone as a camera on macOS, enable the Continuity Camera feature:

  • Ensure your Mac is running macOS 13 or later, and your iPhone is on iOS 16 or later.
  • Sign in both devices with the same Apple ID.
  • Connect your devices with a USB cable or turn on Wi-Fi and Bluetooth for a wireless connection.

For more details, visit Apple support.

Your iPhone should be detected automatically when running the camera setup script in the next section.

< > Update on GitHub