Skip to content
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

Camera Factory Pattern Adoption #64

Merged
merged 19 commits into from
Nov 28, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
12 changes: 6 additions & 6 deletions modules/camera/camera_picamera2.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import numpy as np

# picamera2 module may not exist
# Picamera2 library only exists on Raspberry Pi
try:
import picamera2
except ImportError:
Expand Down Expand Up @@ -33,10 +33,8 @@ def create(cls, width: int, height: int) -> "tuple[True, CameraPiCamera2] | tupl
try:
camera = picamera2.Picamera2()

# Unintuitively, "RGB888" is layout BGR
# See section 4.2.2.2 of the Picamera2 manual
config = camera.create_still_configuration(
{"size": (width, height), "format": "BGR888"}
{"size": (width, height), "format": "RGB888"}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add parameters for "ExposureTime" and "AnalogueGain"? We will need to set these for the IR camera detection

)
camera.configure(config)
camera.start()
Expand Down Expand Up @@ -64,8 +62,10 @@ def run(self) -> tuple[True, np.ndarray] | tuple[False, None]:

Return: Success, image with shape (height, width, channels in BGR).
"""
result, image_data = self.__camera.capture_array()
if not result:
try:
# 1 second before timeout
image_data = self.__camera.capture_array(wait=1)
Xierumeng marked this conversation as resolved.
Show resolved Hide resolved
except TimeoutError:
return False, None

return True, image_data
6 changes: 4 additions & 2 deletions tests/integration/test_camera_opencv.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@
Test OpenCV camera physically.
"""

import pathlib

import cv2

from modules.camera import camera_factory


# TODO: ...
IMAGE_LOG_PREFIX = ...
# TODO: Add camera logging
IMAGE_LOG_PREFIX = pathlib.Path("logs", "test_log_image")
Xierumeng marked this conversation as resolved.
Show resolved Hide resolved


def main() -> int:
Expand Down
6 changes: 4 additions & 2 deletions tests/integration/test_camera_picamera2.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@
Test Picamera2 camera physically.
"""

import pathlib

import cv2

from modules.camera import camera_factory


# TODO: ...
IMAGE_LOG_PREFIX = ...
# TODO: Add camera logging
IMAGE_LOG_PREFIX = pathlib.Path("logs", "test_log_image")
Xierumeng marked this conversation as resolved.
Show resolved Hide resolved


def main() -> int:
Expand Down