49 lines
1.9 KiB
Python
49 lines
1.9 KiB
Python
# Copyright 2024 The HuggingFace Inc. team. All rights reserved.
|
|
#
|
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
# you may not use this file except in compliance with the License.
|
|
# You may obtain a copy of the License at
|
|
#
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
#
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
# See the License for the specific language governing permissions and
|
|
# limitations under the License.
|
|
|
|
from dataclasses import dataclass
|
|
from lerobot.cameras.configs import CameraConfig, ColorMode, Cv2Rotation
|
|
|
|
|
|
@CameraConfig.register_subclass("uf::umi_camera")
|
|
@dataclass
|
|
class UmiCameraConfig(CameraConfig):
|
|
serial_number: str
|
|
color_mode: ColorMode = ColorMode.RGB
|
|
use_depth: bool = False
|
|
rotation: Cv2Rotation = Cv2Rotation.NO_ROTATION
|
|
warmup_s: int = 1
|
|
|
|
def __post_init__(self) -> None:
|
|
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."
|
|
)
|
|
|
|
values = (self.fps, self.width, self.height)
|
|
if any(v is not None for v in values) and any(v is None for v in values):
|
|
raise ValueError(
|
|
"For `fps`, `width` and `height`, either all of them need to be set, or none of them."
|
|
)
|