Skip to content

Commit a050d44

Browse files
committed
run fmt
1 parent 1abc822 commit a050d44

File tree

21 files changed

+279
-275
lines changed

21 files changed

+279
-275
lines changed

src/arduino/app_bricks/object_detection/examples/object_detection_example.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,4 @@
2323
bounding_box = obj_det.get("bounding_box_xyxy", None)
2424

2525
# Draw the bounding boxes
26-
out_image = draw_bounding_boxes(img, out)
26+
out_image = draw_bounding_boxes(img, out)

src/arduino/app_bricks/visual_anomaly_detection/examples/visual_anomaly_example.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,4 @@
2121
bounding_box = anomaly.get("bounding_box_xyxy", None)
2222

2323
# Draw the bounding boxes
24-
out_image = draw_anomaly_markers(img, out)
24+
out_image = draw_anomaly_markers(img, out)

src/arduino/app_peripherals/camera/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from .ip_camera import IPCamera
88
from .websocket_camera import WebSocketCamera
99
from .errors import *
10-
10+
1111
__all__ = [
1212
"Camera",
1313
"V4LCamera",
@@ -18,4 +18,4 @@
1818
"CameraOpenError",
1919
"CameraConfigError",
2020
"CameraTransformError",
21-
]
21+
]

src/arduino/app_peripherals/camera/base_camera.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,15 @@
1818
class BaseCamera(ABC):
1919
"""
2020
Abstract base class for camera implementations.
21-
21+
2222
This class defines the common interface that all camera implementations must follow,
2323
providing a unified API regardless of the underlying camera protocol or type.
2424
"""
2525

2626
def __init__(
2727
self,
2828
resolution: Optional[Tuple[int, int]] = (640, 480),
29-
fps: int = 10,
29+
fps: int = 10,
3030
adjustments: Optional[Callable[[np.ndarray], np.ndarray]] = None,
3131
):
3232
"""
@@ -53,7 +53,7 @@ def start(self) -> None:
5353
with self._camera_lock:
5454
if self._is_started:
5555
return
56-
56+
5757
try:
5858
self._open_camera()
5959
self._is_started = True
@@ -67,7 +67,7 @@ def stop(self) -> None:
6767
with self._camera_lock:
6868
if not self._is_started:
6969
return
70-
70+
7171
try:
7272
self._close_camera()
7373
self._is_started = False
@@ -99,19 +99,19 @@ def _extract_frame(self) -> Optional[np.ndarray]:
9999

100100
if not self._is_started:
101101
return None
102-
102+
103103
frame = self._read_frame()
104104
if frame is None:
105105
return None
106-
106+
107107
self._last_capture_time = time.monotonic()
108-
108+
109109
if self.adjustments is not None:
110110
try:
111111
frame = self.adjustments(frame)
112112
except Exception as e:
113113
raise CameraTransformError(f"Frame transformation failed ({self.adjustments}): {e}")
114-
114+
115115
return frame
116116

117117
def is_started(self) -> bool:

src/arduino/app_peripherals/camera/camera.py

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
class Camera:
1313
"""
1414
Unified Camera class that can be configured for different camera types.
15-
15+
1616
This class serves as both a factory and a wrapper, automatically creating
1717
the appropriate camera implementation based on the provided configuration.
1818
@@ -24,10 +24,10 @@ class Camera:
2424
Note: constructor arguments (except source) must be provided in keyword
2525
format to forward them correctly to the specific camera implementations.
2626
"""
27-
27+
2828
def __new__(cls, source: Union[str, int] = 0, **kwargs) -> BaseCamera:
2929
"""Create a camera instance based on the source type.
30-
30+
3131
Args:
3232
source (Union[str, int]): Camera source identifier. Supports:
3333
- int: V4L camera index (e.g., 0, 1)
@@ -36,7 +36,7 @@ def __new__(cls, source: Union[str, int] = 0, **kwargs) -> BaseCamera:
3636
- str: WebSocket URL for input streams (e.g., "ws://0.0.0.0:8080")
3737
**kwargs: Camera-specific configuration parameters grouped by type:
3838
Common Parameters:
39-
resolution (tuple, optional): Frame resolution as (width, height).
39+
resolution (tuple, optional): Frame resolution as (width, height).
4040
Default: (640, 480)
4141
fps (int, optional): Target frames per second. Default: 10
4242
adjustments (callable, optional): Function pipeline to adjust frames that takes a
@@ -52,57 +52,61 @@ def __new__(cls, source: Union[str, int] = 0, **kwargs) -> BaseCamera:
5252
host (str, optional): WebSocket server host. Default: "0.0.0.0"
5353
port (int, optional): WebSocket server port. Default: 8080
5454
timeout (float, optional): Connection timeout in seconds. Default: 10.0
55-
frame_format (str, optional): Expected frame format ("base64", "binary",
55+
frame_format (str, optional): Expected frame format ("base64", "binary",
5656
"json"). Default: "base64"
57-
57+
5858
Returns:
5959
BaseCamera: Appropriate camera implementation instance
60-
60+
6161
Raises:
6262
CameraConfigError: If source type is not supported or parameters are invalid
6363
CameraOpenError: If the camera cannot be opened
64-
64+
6565
Examples:
6666
V4L Camera:
67-
67+
6868
```python
6969
camera = Camera(0, resolution=(640, 480), fps=30)
7070
camera = Camera("/dev/video1", fps=15)
7171
```
72-
72+
7373
IP Camera:
74-
74+
7575
```python
7676
camera = Camera("rtsp://192.168.1.100:554/stream", username="admin", password="secret", timeout=15.0)
7777
camera = Camera("http://192.168.1.100:8080/video.mp4")
7878
```
79-
79+
8080
WebSocket Camera:
81-
82-
```python
81+
82+
```python
8383
camera = Camera("ws://0.0.0.0:8080", frame_format="json")
8484
camera = Camera("ws://192.168.1.100:8080", timeout=5)
8585
```
8686
"""
8787
if isinstance(source, int) or (isinstance(source, str) and source.isdigit()):
8888
# V4L Camera
8989
from .v4l_camera import V4LCamera
90+
9091
return V4LCamera(source, **kwargs)
9192
elif isinstance(source, str):
9293
parsed = urlparse(source)
93-
if parsed.scheme in ['http', 'https', 'rtsp']:
94+
if parsed.scheme in ["http", "https", "rtsp"]:
9495
# IP Camera
9596
from .ip_camera import IPCamera
97+
9698
return IPCamera(source, **kwargs)
97-
elif parsed.scheme in ['ws', 'wss']:
99+
elif parsed.scheme in ["ws", "wss"]:
98100
# WebSocket Camera - extract host and port from URL
99101
from .websocket_camera import WebSocketCamera
102+
100103
host = parsed.hostname or "localhost"
101104
port = parsed.port or 8080
102105
return WebSocketCamera(host=host, port=port, **kwargs)
103-
elif source.startswith('/dev/video') or source.isdigit():
106+
elif source.startswith("/dev/video") or source.isdigit():
104107
# V4L device path or index as string
105108
from .v4l_camera import V4LCamera
109+
106110
return V4LCamera(source, **kwargs)
107111
else:
108112
raise CameraConfigError(f"Unsupported camera source: {source}")

src/arduino/app_peripherals/camera/errors.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,32 @@
22
#
33
# SPDX-License-Identifier: MPL-2.0
44

5+
56
class CameraError(Exception):
67
"""Base exception for camera-related errors."""
8+
79
pass
810

911

1012
class CameraOpenError(CameraError):
1113
"""Exception raised when the camera cannot be opened."""
14+
1215
pass
1316

1417

1518
class CameraReadError(CameraError):
1619
"""Exception raised when reading from camera fails."""
20+
1721
pass
1822

1923

2024
class CameraConfigError(CameraError):
2125
"""Exception raised when camera configuration is invalid."""
26+
2227
pass
2328

2429

2530
class CameraTransformError(CameraError):
2631
"""Exception raised when frame transformation fails."""
32+
2733
pass

src/arduino/app_peripherals/camera/examples/1_initialize.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@
77
from arduino.app_peripherals.camera import Camera, V4LCamera
88

99

10-
default = Camera() # Uses default camera (V4L)
10+
default = Camera() # Uses default camera (V4L)
1111

1212
# The following two are equivalent
1313
camera = Camera(2, resolution=(640, 480), fps=15) # Infers camera type
1414
v4l = V4LCamera(2, (640, 480), 15) # Explicitly requests V4L camera
1515

1616
# Note: constructor arguments (except source) must be provided in keyword
17-
# format to forward them correctly to the specific camera implementations.
17+
# format to forward them correctly to the specific camera implementations.

src/arduino/app_peripherals/camera/examples/2_capture_image.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,4 @@
1111
camera = Camera()
1212
camera.start()
1313
image: np.ndarray = camera.capture()
14-
camera.stop()
14+
camera.stop()

src/arduino/app_peripherals/camera/examples/3_capture_video.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,4 @@
1818
image: np.ndarray = camera.capture()
1919
# You can process the image here if needed, e.g save it
2020

21-
camera.stop()
21+
camera.stop()

src/arduino/app_peripherals/camera/examples/4_capture_hls.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
# Capture a freely available HLS playlist for testing
1212
# Note: Public streams can be unreliable and may go offline without notice.
13-
url = 'https://demo.unified-streaming.com/k8s/features/stable/video/tears-of-steel/tears-of-steel.ism/.m3u8'
13+
url = "https://demo.unified-streaming.com/k8s/features/stable/video/tears-of-steel/tears-of-steel.ism/.m3u8"
1414

1515
camera = Camera(url)
1616
camera.start()
@@ -20,4 +20,4 @@
2020
image: np.ndarray = camera.capture()
2121
# You can process the image here if needed, e.g save it
2222

23-
camera.stop()
23+
camera.stop()

0 commit comments

Comments
 (0)