Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 29 additions & 3 deletions src/reachy_mini/media/camera_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,36 @@
import cv2
from cv2_enumerate_cameras import enumerate_cameras

RPICAM = (0x1BCF, 0x28C4) # vid, pid
ARDUCAM = (0x0C45, 0x636D)

def find_camera(
vid: int = 0x0C45,
pid: int = 0x636D,

def find_camera(apiPreference: int = cv2.CAP_ANY) -> cv2.VideoCapture | None:
"""Find and return the Reachy Mini camera.

Args:
apiPreference (int): Preferred API backend for the camera. Default is cv2.CAP_ANY.

Returns:
cv2.VideoCapture | None: A VideoCapture object if the camera is found and opened successfully, otherwise None.

"""
cap = find_camera_by_vid_pid(RPICAM[0], RPICAM[1], apiPreference)
if cap is not None:
fourcc = cv2.VideoWriter_fourcc('M', 'J', 'P', 'G') # type: ignore
cap.set(cv2.CAP_PROP_FOURCC, fourcc)
return cap

cap = find_camera_by_vid_pid(ARDUCAM[0], ARDUCAM[1], apiPreference)
if cap is not None:
return cap

return None


def find_camera_by_vid_pid(
vid: int = RPICAM[0],
pid: int = RPICAM[1],
apiPreference: int = cv2.CAP_ANY,
) -> cv2.VideoCapture | None:
"""Find and return a camera with the specified VID and PID.
Expand Down
1 change: 1 addition & 0 deletions src/reachy_mini/reachy_mini.py
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,7 @@ def look_at_image(
if self.media_manager.camera is None:
raise RuntimeError("Camera is not initialized.")

# TODO this is false for the raspicam for now
assert 0 < u < self.media_manager.camera.resolution[0], (
f"u must be in [0, {self.media_manager.camera.resolution[0]}], got {u}."
)
Expand Down