Skip to content

Commit 8548f09

Browse files
refactor(cameras): remove fps and backend specification find-cameras utils
1 parent fba5271 commit 8548f09

File tree

3 files changed

+7
-27
lines changed

3 files changed

+7
-27
lines changed

lerobot/common/cameras/intel/configuration_realsense.py

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,3 @@ def __post_init__(self):
6969
raise ValueError(
7070
f"One of them must be set: name or serial_number, but {self.name=} and {self.serial_number=} provided."
7171
)
72-
73-
at_least_one_is_not_none = self.fps is not None or self.width is not None or self.height is not None
74-
at_least_one_is_none = self.fps is None or self.width is None or self.height is None
75-
if at_least_one_is_not_none and at_least_one_is_none:
76-
raise ValueError(
77-
"For `fps`, `width` and `height`, either all of them need to be set, or none of them, "
78-
f"but {self.fps=}, {self.width=}, {self.height=} were provided."
79-
)

lerobot/common/cameras/opencv/camera_opencv.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ class OpenCVCamera(Camera):
5959
or port changes, especially on Linux. Use the provided utility script to find
6060
available camera indices or paths:
6161
```bash
62-
NOTE(Steven): Point to future util
62+
python -m lerobot.find_cameras
6363
```
6464
6565
The camera's default settings (FPS, resolution, color mode) are used unless
@@ -132,7 +132,7 @@ def __init__(self, config: OpenCVCameraConfig):
132132
self.logs: dict = {} # NOTE(Steven): Might be removed in the future
133133

134134
self.rotation: int | None = get_cv2_rotation(config.rotation)
135-
self.backend: int = get_cv2_backend()
135+
self.backend: int = get_cv2_backend() # NOTE(Steven): If I specify backend the opencv open fails
136136

137137
def __str__(self) -> str:
138138
"""Returns a string representation of the camera instance."""
@@ -195,7 +195,7 @@ def connect(self):
195195
cv2.setNumThreads(1)
196196

197197
logger.debug(f"Attempting to connect to camera {self.index_or_path} using backend {self.backend}...")
198-
self.videocapture_camera = cv2.VideoCapture(self.index_or_path, self.backend)
198+
self.videocapture_camera = cv2.VideoCapture(self.index_or_path)
199199

200200
if not self.videocapture_camera.isOpened():
201201
self.videocapture_camera.release()
@@ -303,7 +303,7 @@ def find_cameras(
303303
targets_to_scan = list(range(max_index_search_range))
304304

305305
for target in targets_to_scan:
306-
camera = cv2.VideoCapture(target, get_cv2_backend())
306+
camera = cv2.VideoCapture(target)
307307
if camera.isOpened():
308308
default_width = int(camera.get(cv2.CAP_PROP_FRAME_WIDTH))
309309
default_height = int(camera.get(cv2.CAP_PROP_FRAME_HEIGHT))

lerobot/find_cameras.py

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
from lerobot.common.cameras.opencv.configuration_opencv import OpenCVCameraConfig
3333

3434
logger = logging.getLogger(__name__)
35-
logging.basicConfig(level=logging.INFO, format="%(asctime)s - %(levelname)s - %(module)s - %(message)s")
35+
# logging.basicConfig(level=logging.INFO, format="%(asctime)s - %(levelname)s - %(module)s - %(message)s")
3636

3737

3838
def find_all_opencv_cameras() -> List[Dict[str, Any]]:
@@ -160,10 +160,9 @@ def create_camera_instance(cam_meta: Dict[str, Any]) -> Optional[Dict[str, Any]]
160160
default_profile = cam_meta.get("default_stream_profile")
161161
width = default_profile.get("width")
162162
height = default_profile.get("height")
163-
fps = default_profile.get("fps")
164163
instance = None
165164

166-
logger.info(f"Preparing {cam_type} ID {cam_id} with profile: Width={width}, Height={height}, FPS={fps}")
165+
logger.info(f"Preparing {cam_type} ID {cam_id} with profile: Width={width}, Height={height}")
167166

168167
try:
169168
if cam_type == "OpenCV":
@@ -172,7 +171,6 @@ def create_camera_instance(cam_meta: Dict[str, Any]) -> Optional[Dict[str, Any]]
172171
color_mode=ColorMode.RGB,
173172
width=width,
174173
height=height,
175-
fps=fps,
176174
)
177175
instance = OpenCVCamera(cv_config)
178176
elif cam_type == "RealSense":
@@ -181,7 +179,6 @@ def create_camera_instance(cam_meta: Dict[str, Any]) -> Optional[Dict[str, Any]]
181179
color_mode=ColorMode.RGB,
182180
width=width,
183181
height=height,
184-
fps=fps,
185182
)
186183
instance = RealSenseCamera(rs_config)
187184
else:
@@ -191,7 +188,6 @@ def create_camera_instance(cam_meta: Dict[str, Any]) -> Optional[Dict[str, Any]]
191188
if instance:
192189
logger.info(f"Connecting to {cam_type} camera: {cam_id}...")
193190
instance.connect()
194-
time.sleep(0.1)
195191
return {"instance": instance, "meta": cam_meta}
196192
except Exception as e:
197193
logger.error(f"Failed to connect or configure {cam_type} camera {cam_id}: {e}")
@@ -211,11 +207,6 @@ def process_camera_image(
211207

212208
try:
213209
image_data = cam.read()
214-
if image_data is None:
215-
logger.warning(
216-
f"No frame received from {cam_type_str} camera {cam_id_str} at time {current_time:.2f}s."
217-
)
218-
return None
219210

220211
return save_image(
221212
image_data,
@@ -293,8 +284,6 @@ def save_images_from_all_cameras(
293284
if futures:
294285
concurrent.futures.wait(futures)
295286

296-
time.sleep(0.05)
297-
298287
except KeyboardInterrupt:
299288
logger.info("Capture interrupted by user.")
300289
finally:
@@ -360,7 +349,6 @@ def save_images_from_all_cameras(
360349
args = parser.parse_args()
361350

362351
if args.command is None:
363-
364352
default_output_dir = capture_parser.get_default("output_dir")
365353
default_record_time_s = capture_parser.get_default("record_time_s")
366354

@@ -370,4 +358,4 @@ def save_images_from_all_cameras(
370358
camera_type_filter=None,
371359
)
372360
else:
373-
args.func(args)
361+
args.func(args)

0 commit comments

Comments
 (0)