-
Notifications
You must be signed in to change notification settings - Fork 3.2k
refactor(cameras): cameras implementations + tests improvements #1108
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
aliberts
merged 75 commits into
user/aliberts/2025_02_25_refactor_robots
from
refactor/camera_implementations_and_tests_improvements
May 23, 2025
Merged
Changes from 73 commits
Commits
Show all changes
75 commits
Select commit
Hold shift + click to select a range
8a6412b
refactor(cameras): init abc class + config
0b5b438
refactor(cameras): opencv camera init
3297c7e
refactor(cameras): realsense camera init
720a637
chore(dependencies): add pyrealsense2 for macos + cleanup init camera…
6348f0f
refactor(cameras): improvements opencv cam v0.1
imstevenpmwork 35c4b01
test(cameras): add minimal opencv test
imstevenpmwork 15b5d28
refactor(cameras): improvements realsense cam v0.1
imstevenpmwork b089c6d
test(cameras): add minimal realsense test
imstevenpmwork 2af8edc
chore(cameras): delete unused files
imstevenpmwork 3416036
chore(cameras): set timeout to 0 in tests
imstevenpmwork 7f34e1a
refactor(cameras): improvements utils functionalities v0.1
imstevenpmwork ddd8fd3
refactor(cameras): improvements utils functionalities v0.2
imstevenpmwork 904bc61
refactor(cameras): fps, width and height are optional at camera level…
imstevenpmwork dbce247
refactor(cameras): homogeneous depth processing in realsense camera
imstevenpmwork 4675b3c
refactor(cameras): add warm-up, fix defaul args, remove width and hei…
imstevenpmwork 81c49ce
[skip ci] refactor(cameras): add warmup read + images different size …
imstevenpmwork 57c2181
refactor(cameras): add read_depth() for realsense + new compressed bag
imstevenpmwork 2d86812
refactor(cameras): width, fps and height is mandatory to have a value…
imstevenpmwork 27bb7c4
chore(cameras): remove compressed files + filename better managed in …
imstevenpmwork d6d8f29
fix(cameras): correct imports for camera config in scripts
imstevenpmwork dae5f7c
chore(tests): explicit cameras artefacts in gitattributes
imstevenpmwork cca6473
fix(tests): kill thread when camera async_read tests fail
imstevenpmwork 859a369
chore(docs): adress notes + add docs in camera code
imstevenpmwork 6797e1d
fix(cameras): correct validate_width_height logic
imstevenpmwork 5daf552
fix(cameras): realsense depth post_process channel check
imstevenpmwork f27f5f8
Apply suggestions from code review 1
imstevenpmwork 295b96c
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 1f2cfd3
Apply suggestions from code review camera_realsense.py
imstevenpmwork 05d8825
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 3890c38
Apply suggestions from code review camera_opencv
imstevenpmwork 3a08edd
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 41179d0
chore(cameras): address review comments + make test pass again
imstevenpmwork 85b0dd0
chore(tests): delete fakecam images
imstevenpmwork 9812f2d
chore(cameras): rename intel -> realsense
imstevenpmwork 525cd68
chore(cameras): fix imports renamed folder + add camera configs in ut…
imstevenpmwork ab7565a
chore(cameras): refactor utility function dictionary fetching style
imstevenpmwork efd2849
chore(tests): add ids to parametrize
imstevenpmwork 99ea24d
chore(cameras): move connect under is_connected
imstevenpmwork 39f908e
chore(cameras): move if check out of _validate functions
imstevenpmwork b3dafcf
docs(cameras): update depth related example
imstevenpmwork 39a93a7
docs(cameras): update arg in class doc
imstevenpmwork 18b56e1
refactor(cameras): realsense config arg serial_number_or_name
imstevenpmwork 7a4b9f0
chore(cameras): rename prerotated_ to capture_ var names
imstevenpmwork eb2d967
docs(cameras): add explanation of warmup arg in connect
imstevenpmwork a653210
chore(cameras): move _stop_thread under _start_thread methods
imstevenpmwork 91a5faf
feat(cameras): add check for fps, height and width in realsenseconfig…
imstevenpmwork 33b8559
refactor(cameras): move find_cameras to the base class
imstevenpmwork a36536d
Apply suggestions from code review 3
imstevenpmwork 1c90cd1
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 76f661f
chore(robots): fix pre-commit
imstevenpmwork 7f7c431
docs(cameras): update find_cameras instructions
imstevenpmwork f8c7e59
test(cameras): use fixture for realsense patching + depth read test
imstevenpmwork 73bb970
chore(cameras): remove 14 logs
imstevenpmwork 95a9518
Merge branch 'user/aliberts/2025_02_25_refactor_robots' into refactor…
imstevenpmwork 625bb9c
chore(cameras): try import rs protect
imstevenpmwork 95f3e53
chore(test): try import rs protect
imstevenpmwork 47d5008
chore(cameras): address unresolved conversations
imstevenpmwork 4d9825b
fix(ci): change default opencv backend
imstevenpmwork 0c411a6
[skip ci] doc(tests): add comment related to test duration
imstevenpmwork 65ad065
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 5857952
fix(cameras): remove rs from signatures
imstevenpmwork 22e98a6
Apply suggestions from code review (logging statements)
imstevenpmwork bf09993
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 96d9c40
chore(cameras): address PR comments 2
imstevenpmwork 2429b80
chore(cameras): remove wrmup arg none check realsense
imstevenpmwork e556c97
chore(cameras): dir path find_cameras
imstevenpmwork 0a997d9
Apply suggestions from code review tests+utils
imstevenpmwork efe9553
[skip-ci] fix(cameras): find camera utils arg name
imstevenpmwork c050a07
Merge branch 'user/aliberts/2025_02_25_refactor_robots' into refactor…
imstevenpmwork 0fcaf21
chore(cameras): remove unused utils function
imstevenpmwork 2bf433a
chore(cameras): remove rmtree in find_cameras
imstevenpmwork fb3b45b
chore(cameras): remove width and height settings validation
imstevenpmwork 1c6b349
refactor(cameras): move from Queue to Lock for read_async()
imstevenpmwork 96ee1c6
Apply suggestions from code review round 3
imstevenpmwork c009136
chore(cameras): remove try/except in read_async()
imstevenpmwork File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,17 @@ | ||
| # 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 .camera import Camera | ||
| from .configs import CameraConfig | ||
| from .configs import CameraConfig, ColorMode, Cv2Rotation | ||
| from .utils import make_cameras_from_configs |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,25 +1,120 @@ | ||
| #!/usr/bin/env 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. | ||
|
|
||
| import abc | ||
| from typing import Any, Dict, List | ||
|
|
||
| import numpy as np | ||
|
|
||
| from .configs import CameraConfig, ColorMode | ||
|
|
||
|
|
||
| class Camera(abc.ABC): | ||
aliberts marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| """Base class for camera implementations. | ||
|
|
||
| Defines a standard interface for camera operations across different backends. | ||
| Subclasses must implement all abstract methods. | ||
|
|
||
| Manages basic camera properties (FPS, resolution) and core operations: | ||
| - Connection/disconnection | ||
| - Frame capture (sync/async) | ||
|
|
||
| Attributes: | ||
| fps (int | None): Configured frames per second | ||
| width (int | None): Frame width in pixels | ||
| height (int | None): Frame height in pixels | ||
|
|
||
| Example: | ||
| class MyCamera(Camera): | ||
| def __init__(self, config): ... | ||
| @property | ||
| def is_connected(self) -> bool: ... | ||
| def connect(self, warmup=True): ... | ||
| # Plus other required methods | ||
| """ | ||
|
|
||
| def __init__(self, config: CameraConfig): | ||
| """Initialize the camera with the given configuration. | ||
|
|
||
| Args: | ||
| config: Camera configuration containing FPS and resolution. | ||
| """ | ||
| self.fps: int | None = config.fps | ||
| self.width: int | None = config.width | ||
| self.height: int | None = config.height | ||
|
|
||
| @property | ||
| @abc.abstractmethod | ||
aliberts marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| def connect(self): | ||
| def is_connected(self) -> bool: | ||
| """Check if the camera is currently connected. | ||
|
|
||
| Returns: | ||
| bool: True if the camera is connected and ready to capture frames, | ||
| False otherwise. | ||
| """ | ||
| pass | ||
|
|
||
| @staticmethod | ||
| @abc.abstractmethod | ||
| def read(self, temporary_color: str | None = None) -> np.ndarray: | ||
| def find_cameras() -> List[Dict[str, Any]]: | ||
| """Detects available cameras connected to the system. | ||
| Returns: | ||
| List[Dict[str, Any]]: A list of dictionaries, | ||
| where each dictionary contains information about a detected camera. | ||
| """ | ||
| pass | ||
|
|
||
| @abc.abstractmethod | ||
| def async_read(self) -> np.ndarray: | ||
| def connect(self, warmup: bool = True) -> None: | ||
| """Establish connection to the camera. | ||
|
|
||
| Args: | ||
| warmup: If True (default), captures a warmup frame before returning. Useful | ||
| for cameras that require time to adjust capture settings. | ||
| If False, skips the warmup frame. | ||
| """ | ||
| pass | ||
|
|
||
| @abc.abstractmethod | ||
| def read(self, color_mode: ColorMode | None = None) -> np.ndarray: | ||
| """Capture and return a single frame from the camera. | ||
|
|
||
| Args: | ||
| color_mode: Desired color mode for the output frame. If None, | ||
| uses the camera's default color mode. | ||
|
|
||
| Returns: | ||
| np.ndarray: Captured frame as a numpy array. | ||
| """ | ||
| pass | ||
|
|
||
| @abc.abstractmethod | ||
| def disconnect(self): | ||
| def async_read(self, timeout_ms: float = ...) -> np.ndarray: | ||
| """Asynchronously capture and return a single frame from the camera. | ||
|
|
||
| Args: | ||
| timeout_ms: Maximum time to wait for a frame in milliseconds. | ||
| Defaults to implementation-specific timeout. | ||
|
|
||
| Returns: | ||
| np.ndarray: Captured frame as a numpy array. | ||
| """ | ||
| pass | ||
|
|
||
| def __del__(self): | ||
| if getattr(self, "is_connected", False): | ||
| self.disconnect() | ||
| @abc.abstractmethod | ||
| def disconnect(self) -> None: | ||
| """Disconnect from the camera and release resources.""" | ||
| pass | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,11 +1,44 @@ | ||
| #!/usr/bin/env 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. | ||
|
|
||
| import abc | ||
| from dataclasses import dataclass | ||
| from enum import Enum | ||
|
|
||
| import draccus | ||
|
|
||
|
|
||
| @dataclass | ||
| class ColorMode(str, Enum): | ||
| RGB = "rgb" | ||
| BGR = "bgr" | ||
|
|
||
|
|
||
| class Cv2Rotation(int, Enum): | ||
| NO_ROTATION = 0 | ||
| ROTATE_90 = 90 | ||
| ROTATE_180 = 180 | ||
| ROTATE_270 = -90 | ||
|
|
||
|
|
||
| @dataclass(kw_only=True) | ||
| class CameraConfig(draccus.ChoiceRegistry, abc.ABC): | ||
| fps: int | None = None | ||
| width: int | None = None | ||
| height: int | None = None | ||
|
|
||
| @property | ||
| def type(self) -> str: | ||
| return self.get_choice_name(self.__class__) |
aliberts marked this conversation as resolved.
Show resolved
Hide resolved
|
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.