forked from tangger/lerobot
Fix camera FPS set issue (#2275)
Set camera width/height 1st before FPS setting, to avoid FPS set failure alike: ERROR:__main__:Failed to connect or configure OpenCV camera /dev/video2: OpenCVCamera(/dev/video2) failed to set fps=30 (actual_fps=25.0).
This commit is contained in:
@@ -208,11 +208,6 @@ class OpenCVCamera(Camera):
|
|||||||
if self.videocapture is None:
|
if self.videocapture is None:
|
||||||
raise DeviceNotConnectedError(f"{self} videocapture is not initialized")
|
raise DeviceNotConnectedError(f"{self} videocapture is not initialized")
|
||||||
|
|
||||||
if self.fps is None:
|
|
||||||
self.fps = self.videocapture.get(cv2.CAP_PROP_FPS)
|
|
||||||
else:
|
|
||||||
self._validate_fps()
|
|
||||||
|
|
||||||
default_width = int(round(self.videocapture.get(cv2.CAP_PROP_FRAME_WIDTH)))
|
default_width = int(round(self.videocapture.get(cv2.CAP_PROP_FRAME_WIDTH)))
|
||||||
default_height = int(round(self.videocapture.get(cv2.CAP_PROP_FRAME_HEIGHT)))
|
default_height = int(round(self.videocapture.get(cv2.CAP_PROP_FRAME_HEIGHT)))
|
||||||
|
|
||||||
@@ -225,6 +220,11 @@ class OpenCVCamera(Camera):
|
|||||||
else:
|
else:
|
||||||
self._validate_width_and_height()
|
self._validate_width_and_height()
|
||||||
|
|
||||||
|
if self.fps is None:
|
||||||
|
self.fps = self.videocapture.get(cv2.CAP_PROP_FPS)
|
||||||
|
else:
|
||||||
|
self._validate_fps()
|
||||||
|
|
||||||
def _validate_fps(self) -> None:
|
def _validate_fps(self) -> None:
|
||||||
"""Validates and sets the camera's frames per second (FPS)."""
|
"""Validates and sets the camera's frames per second (FPS)."""
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user