Skip to content

Commit 91f4219

Browse files
committed
add examples
1 parent f4a9a53 commit 91f4219

File tree

8 files changed

+118
-56
lines changed

8 files changed

+118
-56
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# SPDX-FileCopyrightText: Copyright (C) 2025 ARDUINO SA <http://www.arduino.cc>
2+
#
3+
# SPDX-License-Identifier: MPL-2.0
4+
5+
# EXAMPLE_NAME = "Initialize camera input"
6+
# EXAMPLE_REQUIRES = "Requires a connected camera"
7+
from arduino.app_peripherals.camera import Camera, V4LCamera
8+
9+
10+
default = Camera() # Uses default camera (V4L)
11+
12+
# The following two are equivalent
13+
camera = Camera(2, resolution=(640, 480), fps=15) # Infers camera type
14+
v4l = V4LCamera(2, (640, 480), 15) # Explicitly requests V4L camera
15+
16+
# Note: constructor arguments (except source) must be provided in keyword
17+
# format to forward them correctly to the specific camera implementations.
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# SPDX-FileCopyrightText: Copyright (C) 2025 ARDUINO SA <http://www.arduino.cc>
2+
#
3+
# SPDX-License-Identifier: MPL-2.0
4+
5+
# EXAMPLE_NAME = "Capture an image"
6+
# EXAMPLE_REQUIRES = "Requires a connected camera"
7+
import numpy as np
8+
from arduino.app_peripherals.camera import Camera
9+
10+
11+
camera = Camera()
12+
camera.start()
13+
image: np.ndarray = camera.capture()
14+
camera.stop()
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# SPDX-FileCopyrightText: Copyright (C) 2025 ARDUINO SA <http://www.arduino.cc>
2+
#
3+
# SPDX-License-Identifier: MPL-2.0
4+
5+
# EXAMPLE_NAME = "Capture a video"
6+
# EXAMPLE_REQUIRES = "Requires a connected camera"
7+
import time
8+
import numpy as np
9+
from arduino.app_peripherals.camera import Camera
10+
11+
12+
# Capture a video for 5 seconds at 15 FPS
13+
camera = Camera(fps=15)
14+
camera.start()
15+
16+
start_time = time.time()
17+
while time.time() - start_time < 5:
18+
image: np.ndarray = camera.capture()
19+
# You can process the image here if needed, e.g save it
20+
21+
camera.stop()
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# SPDX-FileCopyrightText: Copyright (C) 2025 ARDUINO SA <http://www.arduino.cc>
2+
#
3+
# SPDX-License-Identifier: MPL-2.0
4+
5+
# EXAMPLE_NAME = "Capture an HLS (HTTP Live Stream) video"
6+
import time
7+
import numpy as np
8+
from arduino.app_peripherals.camera import Camera
9+
10+
11+
# Capture a freely available HLS playlist for testing
12+
# 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'
14+
15+
camera = Camera(url)
16+
camera.start()
17+
18+
start_time = time.time()
19+
while time.time() - start_time < 5:
20+
image: np.ndarray = camera.capture()
21+
# You can process the image here if needed, e.g save it
22+
23+
camera.stop()
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# SPDX-FileCopyrightText: Copyright (C) 2025 ARDUINO SA <http://www.arduino.cc>
2+
#
3+
# SPDX-License-Identifier: MPL-2.0
4+
5+
# EXAMPLE_NAME = "Capture an RTSP (Real-Time Streaming Protocol) video"
6+
import time
7+
import numpy as np
8+
from arduino.app_peripherals.camera import Camera
9+
10+
11+
# Capture a freely available RTSP stream for testing
12+
# Note: Public streams can be unreliable and may go offline without notice.
13+
url = "rtsp://170.93.143.139/rtplive/470011e600ef003a004ee33696235daa"
14+
15+
camera = Camera(url)
16+
camera.start()
17+
18+
start_time = time.time()
19+
while time.time() - start_time < 5:
20+
image: np.ndarray = camera.capture()
21+
# You can process the image here if needed, e.g save it
22+
23+
camera.stop()
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# SPDX-FileCopyrightText: Copyright (C) 2025 ARDUINO SA <http://www.arduino.cc>
2+
#
3+
# SPDX-License-Identifier: MPL-2.0
4+
5+
# EXAMPLE_NAME = "Capture an input WebSocket video"
6+
import time
7+
import numpy as np
8+
from arduino.app_peripherals.camera import Camera
9+
10+
11+
# Expose a WebSocket camera stream for clients to connect to and consume it
12+
camera = Camera("ws://0.0.0.0:8080", timeout=5)
13+
camera.start()
14+
15+
start_time = time.time()
16+
while time.time() - start_time < 5:
17+
image: np.ndarray = camera.capture()
18+
# You can process the image here if needed, e.g save it
19+
20+
camera.stop()

src/arduino/app_peripherals/camera/examples/hls.py

Lines changed: 0 additions & 22 deletions
This file was deleted.

src/arduino/app_peripherals/camera/examples/rtsp.py

Lines changed: 0 additions & 34 deletions
This file was deleted.

0 commit comments

Comments
 (0)