forked from tangger/lerobot
47 lines
1.5 KiB
Python
47 lines
1.5 KiB
Python
from dataclasses import dataclass
|
|
from pathlib import Path
|
|
|
|
from ..configs import CameraConfig, ColorMode, Cv2Rotation
|
|
|
|
|
|
@CameraConfig.register_subclass("opencv")
|
|
@dataclass
|
|
class OpenCVCameraConfig(CameraConfig):
|
|
"""
|
|
Example of tested options for Intel Real Sense D405:
|
|
|
|
```python
|
|
OpenCVCameraConfig(0, 30, 640, 480)
|
|
OpenCVCameraConfig(0, 60, 640, 480)
|
|
OpenCVCameraConfig(0, 90, 640, 480)
|
|
OpenCVCameraConfig(0, 30, 1280, 720)
|
|
```
|
|
"""
|
|
|
|
index_or_path: int | Path
|
|
fps: int | None = None
|
|
width: int | None = None
|
|
height: int | None = None
|
|
color_mode: ColorMode = ColorMode.RGB
|
|
channels: int = 3 # NOTE(Steven): Why is this a config?
|
|
rotation: Cv2Rotation = Cv2Rotation.NO_ROTATION
|
|
|
|
def __post_init__(self):
|
|
if self.color_mode not in (ColorMode.RGB, ColorMode.BGR):
|
|
raise ValueError(
|
|
f"`color_mode` is expected to be {ColorMode.RGB.value} or {ColorMode.BGR.value}, but {self.color_mode} is provided."
|
|
)
|
|
|
|
if self.rotation not in (
|
|
Cv2Rotation.NO_ROTATION,
|
|
Cv2Rotation.ROTATE_90,
|
|
Cv2Rotation.ROTATE_180,
|
|
Cv2Rotation.ROTATE_270,
|
|
):
|
|
raise ValueError(
|
|
f"`rotation` is expected to be in {(Cv2Rotation.NO_ROTATION, Cv2Rotation.ROTATE_90, Cv2Rotation.ROTATE_180, Cv2Rotation.ROTATE_270)}, but {self.rotation} is provided."
|
|
)
|
|
|
|
if self.channels != 3:
|
|
raise NotImplementedError(f"Unsupported number of channels: {self.channels}")
|