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

Camera Factory Pattern Adoption #64

merged 19 commits into from
Nov 28, 2024

Conversation

bantuerfei0
Copy link
Contributor

  • Removed the ability for cameras to save images, instead they just return data and it is up to the caller to save the data
  • Added implementations for the opencv and picamera2 (UNTESTED) camera
  • Added CameraOption enum (CAM_OPENCV, CAM_PICAM2) to camera_factory.py
  • Added create_camera(CameraOption, width, height) function to camera_factory.py
  • Both untested, however the opencv implementation should be identical to the previous iteration

@bantuerfei0
Copy link
Contributor Author

Note: include import checks inside create_camera() function, not the implementations themselves...?

Copy link
Contributor

@Xierumeng Xierumeng left a comment

Choose a reason for hiding this comment

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

Reviewed.

modules/camera/base_camera.py Outdated Show resolved Hide resolved
modules/camera/base_camera.py Outdated Show resolved Hide resolved
modules/camera/base_camera.py Show resolved Hide resolved
class BaseCameraDevice(ABC):
"""
Abstract class for camera device implementations.
TODO: could leverage the abc library's tags more (required properties/methods/etc.)
Copy link
Contributor

Choose a reason for hiding this comment

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

Why not do this now in this PR?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nevermind, just read up on it and the abstractproperty decorator is deprecated since python 3.3

We can just use the @Property decorator. However, I believe camera is supposed to be "private"

modules/camera/base_camera.py Outdated Show resolved Hide resolved
modules/camera/camera_picamera2.py Outdated Show resolved Hide resolved
modules/camera/camera_picamera2.py Outdated Show resolved Hide resolved
modules/camera/camera_picamera2.py Outdated Show resolved Hide resolved
modules/camera/camera_picamera2.py Outdated Show resolved Hide resolved
modules/camera/camera_picamera2.py Outdated Show resolved Hide resolved
The picamera2 library seems to throw RuntimeError if anything goes wrong, so wrapping the camera creation in a try-except block.

Picamera2 fails capture_array() the same way opencv would for read()

Changed the configuration for the picamera2 camera to use a still configuration. TL;DR most configurations are similar in parameters, except for buffer size. See manual/source for more
@bantuerfei0
Copy link
Contributor Author

Integration tests are failing, going to go to work session today to fix

Tested OpenCV integration test

Tested QR Code integration test

Pending Picamera2 integration test

Renamed get_camera_data function inside cameras to "run"

Fixed type hinting error in picamera2 implementation

Other small changes
Copy link
Contributor

@Xierumeng Xierumeng left a comment

Choose a reason for hiding this comment

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

Reviewed.

modules/camera/base_camera.py Show resolved Hide resolved
modules/camera/base_camera.py Outdated Show resolved Hide resolved
modules/camera/base_camera.py Outdated Show resolved Hide resolved
modules/camera/base_camera.py Outdated Show resolved Hide resolved
modules/camera/base_camera.py Outdated Show resolved Hide resolved
tests/integration/test_camera_opencv.py Outdated Show resolved Hide resolved
tests/integration/test_camera_picamera2.py Outdated Show resolved Hide resolved
tests/integration/test_camera_picamera2.py Show resolved Hide resolved
tests/integration/test_camera_picamera2.py Outdated Show resolved Hide resolved
tests/integration/test_camera_qr_example.py Outdated Show resolved Hide resolved
Copy link
Contributor

@Xierumeng Xierumeng left a comment

Choose a reason for hiding this comment

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

Also these.

modules/camera/camera_opencv.py Outdated Show resolved Hide resolved
modules/camera/camera_picamera2.py Outdated Show resolved Hide resolved
Copy link
Contributor

@Xierumeng Xierumeng left a comment

Choose a reason for hiding this comment

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

Reviewed.

modules/camera/base_camera.py Outdated Show resolved Hide resolved
modules/camera/base_camera.py Show resolved Hide resolved
modules/camera/base_camera.py Outdated Show resolved Hide resolved
modules/camera/base_camera.py Outdated Show resolved Hide resolved
modules/camera/camera_opencv.py Outdated Show resolved Hide resolved
modules/camera/camera_picamera2.py Outdated Show resolved Hide resolved
modules/camera/camera_picamera2.py Show resolved Hide resolved
tests/integration/test_camera_opencv.py Outdated Show resolved Hide resolved
tests/integration/test_camera_picamera2.py Outdated Show resolved Hide resolved
tests/integration/test_camera_qr_example.py Outdated Show resolved Hide resolved
Copy link
Contributor

@Xierumeng Xierumeng left a comment

Choose a reason for hiding this comment

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

Reviewed.

modules/camera/camera_picamera2.py Outdated Show resolved Hide resolved
tests/integration/test_camera_opencv.py Outdated Show resolved Hide resolved
tests/integration/test_camera_picamera2.py Outdated Show resolved Hide resolved
Copy link
Member

@maxlou05 maxlou05 left a comment

Choose a reason for hiding this comment

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

Just one little thing

camera = picamera2.Picamera2()

config = camera.create_still_configuration(
{"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

Copy link
Contributor

@Xierumeng Xierumeng left a comment

Choose a reason for hiding this comment

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

Reviewed.

modules/camera/camera_picamera2.py Outdated Show resolved Hide resolved
Copy link
Member

@maxlou05 maxlou05 left a comment

Choose a reason for hiding this comment

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

Approved

@maxlou05 maxlou05 mentioned this pull request Nov 28, 2024
@bantuerfei0 bantuerfei0 merged commit 0dfb0f7 into main Nov 28, 2024
1 check passed
@bantuerfei0 bantuerfei0 deleted the camera-factory-pattern branch November 28, 2024 19:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants