-
Notifications
You must be signed in to change notification settings - Fork 8
camera config classes #73
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
Conversation
maxlou05
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be an empty file. Also, we don't import classes directly, we only import the modules then use module.Class later on in the code. Manually include the imports in each file, and only 1 module per line
modules/camera/camera_config.py
Outdated
| class OpenCVCameraConfig: | ||
| """ | ||
| Placeholder | ||
| """ No newline at end of file |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add a newline at the end of the file. Also, are empty classes are not allowed in Python, you need to add pass to it otherwise it throws error.
modules/camera/camera_factory.py
Outdated
| camera_option: CameraOption, width: int, height: int | ||
| ) -> tuple[True, base_camera.BaseCameraDevice] | tuple[False, None]: | ||
| camera_option: CameraOption, width: int, height: int, config: None | ||
| ) -> tuple[True, base_camera.BaseCameraDevice | None] | tuple[False, None]: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should never return True if returning Camera device failed to instatiate, that's why it was setup like this. No need to change the output type
modules/camera/camera_factory.py
Outdated
| def create_camera( | ||
| camera_option: CameraOption, width: int, height: int | ||
| ) -> tuple[True, base_camera.BaseCameraDevice] | tuple[False, None]: | ||
| camera_option: CameraOption, width: int, height: int, config: None |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
config type should be [camera_config.PiCameraConfig | camera_config.OpenCVCameraConfig]
|
|
||
| def test_opencv_camera_config() -> None: | ||
| config = OpenCVCameraConfig() | ||
| assert config is not None No newline at end of file |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add empty line at end of file
| config = camera.create_still_configuration( | ||
| camera_config = camera.create_still_configuration( | ||
| {"size": (width, height), "format": "RGB888"} | ||
| ) | ||
| camera.configure(config) | ||
| camera.configure(camera_config) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you change this portion to create_preview_configuration(). If you don't want to make a new name, you can also combine the whole thing together into a line
modules/camera/__init__.py
Outdated
| "OpenCVCameraConfig", | ||
| "CameraOpenCV", | ||
| "CameraPiCamera2", | ||
| ] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add newline to the bottom of the file
modules/camera/camera_config.py
Outdated
| """ | ||
| Dictionary containing camera controls. | ||
| """ | ||
| controls: dict[str, int | float | None] = {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It doesn't need to have a None type, as it just won't exist in the dictionary
maxlou05
left a comment
There was a problem hiding this 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_config.py
Outdated
| controls["Contrast"] = self.contrast | ||
| if self.lens_position is not None: | ||
| controls["LensPosition"] = self.lens_position | ||
| controls["AfMode"] = controls.AfModeEnum.Manual |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you need to import the library at the top of this file:
try:
from libcamera import controls # This is a pre-installed library on the Rpi5
except:
pass
But, this means you probably should rename your dictionary to something else like camera_controls or settings
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you don't need this file, just modify test_camera_picamera2.py, test_camera_opencv.py and test_camera_qr_exmaple.py (all in the tests/integration folder) to use the camera configs.
|
|
||
| from modules.camera import camera_factory | ||
|
|
||
| from modules.camera.camera_config import PiCameraConfig |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No space above this line, and also should be from modules.camera import camera_config since we import modules
modules/camera/camera_factory.py
Outdated
| """ | ||
| match camera_option: | ||
| case CameraOption.OPENCV: | ||
| return camera_opencv.CameraOpenCV.create(width, height) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In camera_opencv.py just make create take in a config Object as well, and then write a comment #TODO: apply camera configs to camera here to indicate it will be done sometime in the future
maxlou05
left a comment
There was a problem hiding this 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
| @abc.abstractmethod | ||
| def create( | ||
| cls, width: int, height: int | ||
| cls, width: int, height: int, config: object |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Type of config should be camera_config.PiCameraConfig | camera_config.OpenCVCameraConfig
modules/camera/camera_config.py
Outdated
| try: | ||
| from libcamera import controls # This is a pre-installed library on the Rpi5 | ||
| except ImportError: | ||
| pass # pylint: disable=bare-except |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are you sure you still need the bare-except disable? If not, then remove it
modules/camera/camera_opencv.py
Outdated
| import numpy as np | ||
|
|
||
| from . import base_camera | ||
| from .camera_config import OpenCVCameraConfig |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just from . import camera_config
modules/camera/camera_opencv.py
Outdated
| def create( | ||
| cls, width: int, height: int, config: OpenCVCameraConfig | ||
| ) -> "tuple[True, CameraOpenCV] | tuple[False, None]": | ||
| # TODO: apply camera configs to camera here |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you move this comment to line 32, where you wrote the placeholder?
modules/camera/camera_opencv.py
Outdated
| @classmethod | ||
| def create(cls, width: int, height: int) -> "tuple[True, CameraOpenCV] | tuple[False, None]": | ||
| def create( | ||
| cls, width: int, height: int, config: OpenCVCameraConfig |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Make config an optional argument defaulted to None
|
|
||
| from modules.camera import camera_factory | ||
|
|
||
| from modules.camera import camera_factory, camera_config |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please separate into 2 lines, and also keep 2 spaces between the imports and global constants.
from modules.camera import camera_factory
from modules.camera import camera_config
IMAGE_LOG_PREFIX = ...
| try: | ||
| assert config is not None | ||
| except AssertionError as e: | ||
| print(f"Configuration test failed: {e}") | ||
| return -1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's fine to just keep the assert line. We don't need to catch exception here, as this is an integration test.
| try: | ||
| assert config.exposure_time == 250 | ||
| assert config.contrast == 1.0 | ||
| assert config.analogue_gain == 64.0 | ||
| assert config.lens_position is None | ||
| except AssertionError as e: | ||
| print(f"Configuration test failed: {e}") | ||
| return -1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here, just keep the assert lines, no need to catch the exception since this is a test
|
|
||
| from modules.camera import camera_factory | ||
|
|
||
| from modules.camera import camera_factory, camera_config |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here: separate into 2 lines and make sure 2 spaces between imports and global constants
| import cv2 | ||
|
|
||
| from modules.camera import camera_factory | ||
| from modules.camera import camera_factory, camera_config |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Separate into 2 lines
maxlou05
left a comment
There was a problem hiding this 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
| from . import camera_configurations | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you move these to line 15 (so that our libraries are grouped together, and 2 lines before constants)
maxlou05
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Approved!
maxlou05
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Approved
No description provided.