81 lines
3.3 KiB
Python
81 lines
3.3 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 ..configs import CameraConfig, ColorMode, Cv2Rotation
|
|
|
|
|
|
@CameraConfig.register_subclass("intelrealsense")
|
|
@dataclass
|
|
class RealSenseCameraConfig(CameraConfig):
|
|
"""
|
|
Example of tested options for Intel Real Sense D405:
|
|
|
|
```python
|
|
RealSenseCameraConfig(128422271347, 30, 640, 480)
|
|
RealSenseCameraConfig(128422271347, 60, 640, 480)
|
|
RealSenseCameraConfig(128422271347, 90, 640, 480)
|
|
RealSenseCameraConfig(128422271347, 30, 1280, 720)
|
|
RealSenseCameraConfig(128422271347, 30, 640, 480, use_depth=True)
|
|
RealSenseCameraConfig(128422271347, 30, 640, 480, rotation=90)
|
|
```
|
|
"""
|
|
|
|
name: str | None = None
|
|
serial_number: int | None = None
|
|
fps: int | None = None
|
|
width: int | None = None # NOTE(Steven): Make this not None allowed!
|
|
height: int | None = None
|
|
color_mode: ColorMode = ColorMode.RGB
|
|
channels: int | None = 3
|
|
use_depth: bool = False
|
|
force_hardware_reset: bool = True
|
|
rotation: Cv2Rotation = (
|
|
Cv2Rotation.NO_ROTATION
|
|
) # NOTE(Steven): Check how draccus would deal with this str -> enum
|
|
|
|
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}")
|
|
|
|
# bool is stronger than is None, since it works with empty strings
|
|
if bool(self.name) and bool(self.serial_number):
|
|
raise ValueError(
|
|
f"One of them must be set: name or serial_number, but {self.name=} and {self.serial_number=} provided."
|
|
)
|
|
|
|
at_least_one_is_not_none = self.fps is not None or self.width is not None or self.height is not None
|
|
at_least_one_is_none = self.fps is None or self.width is None or self.height is None
|
|
if at_least_one_is_not_none and at_least_one_is_none:
|
|
raise ValueError(
|
|
"For `fps`, `width` and `height`, either all of them need to be set, or none of them, "
|
|
f"but {self.fps=}, {self.width=}, {self.height=} were provided."
|
|
)
|