mirror of
https://github.com/huggingface/lerobot.git
synced 2026-07-23 17:56:07 +00:00
Set OpenCV fourcc after size and fps (#3620)
* Set OpenCV fourcc after size and fps * Set OpenCV fourcc last on Windows * Add comment explaining DSHOW fourcc ordering
This commit is contained in:
@@ -199,12 +199,13 @@ class OpenCVCamera(Camera):
|
|||||||
DeviceNotConnectedError: If the camera is not connected.
|
DeviceNotConnectedError: If the camera is not connected.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
# Set FOURCC first (if specified) as it can affect available FPS/resolution options
|
|
||||||
if self.config.fourcc is not None:
|
|
||||||
self._validate_fourcc()
|
|
||||||
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")
|
||||||
|
|
||||||
|
set_fourcc_after_size_and_fps = platform.system() == "Windows"
|
||||||
|
if self.config.fourcc is not None and not set_fourcc_after_size_and_fps:
|
||||||
|
self._validate_fourcc()
|
||||||
|
|
||||||
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)))
|
||||||
|
|
||||||
@@ -222,6 +223,11 @@ class OpenCVCamera(Camera):
|
|||||||
else:
|
else:
|
||||||
self._validate_fps()
|
self._validate_fps()
|
||||||
|
|
||||||
|
if self.config.fourcc is not None and set_fourcc_after_size_and_fps:
|
||||||
|
# On Windows with DSHOW, changing the resolution can silently override the FOURCC setting.
|
||||||
|
# Set FOURCC last to make sure the requested pixel format is actually enforced.
|
||||||
|
self._validate_fourcc()
|
||||||
|
|
||||||
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