LeRobot 文档
摄像头
加入 Hugging Face 社区
并获得增强的文档体验
开始使用
摄像头
LeRobot 为视频捕捉提供了多种选择,包括手机摄像头、笔记本电脑内置摄像头、外置网络摄像头和英特尔实感(Intel RealSense)摄像头。要高效地从大多数摄像头录制帧,您可以使用 OpenCVCamera
或 RealSenseCamera
类。有关 OpenCVCamera
类的更多兼容性详情,请参阅 OpenCV 视频 I/O 概述。
查找你的摄像头
要实例化一个摄像头,你需要一个摄像头标识符。这个标识符可能会在你重启电脑或重新插拔摄像头时发生变化,这种行为主要取决于你的操作系统。
要查找插入到你系统中的摄像头的索引,请运行以下脚本:
lerobot-find-cameras opencv # or realsense for Intel Realsense cameras
如果你连接了两个摄像头,输出结果将类似于:
--- 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 ...)
在 `macOS` 中使用英特尔实感摄像头时,你可能会遇到这个 错误:Error finding RealSense cameras: failed to set power state
,这可以通过使用 sudo
权限运行相同的命令来解决。请注意,在 `macOS` 中使用实感摄像头是不稳定的。
使用摄像头
下面是两个示例,演示了如何使用该 API。
- 使用基于 OpenCV 的摄像头进行异步帧捕捉
- 使用英特尔实感摄像头进行彩色和深度捕捉
Open CV 摄像头
英特尔实感摄像头
from lerobot.cameras.opencv.configuration_opencv import OpenCVCameraConfig
from lerobot.cameras.opencv.camera_opencv import OpenCVCamera
from lerobot.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()
使用你的手机
Mac
Linux
要在 macOS 上使用 iPhone 作为摄像头,请启用连续互通相机功能。
- 确保你的 Mac 运行的是 macOS 13 或更高版本,iPhone 运行的是 iOS 16 或更高版本。
- 使用相同的 Apple ID 登录两台设备。
- 使用 USB 数据线连接你的设备,或打开 Wi-Fi 和蓝牙以进行无线连接。
更多详情,请访问 Apple 支持。
在下一节中运行摄像头设置脚本时,你的 iPhone 应该会被自动检测到。