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

integrated camera_factory in video_input #232

Merged
merged 9 commits into from
Dec 22, 2024
8 changes: 4 additions & 4 deletions modules/video_input/video_input.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,22 @@
"""

from .. import image_and_time
from ..common.modules.camera import camera_device
from ..common.modules.camera import camera_factory


class VideoInput:
"""
Combines image and timestamp together.
"""

def __init__(self, camera_name: "int | str", save_name: str = "") -> None:
self.device = camera_device.CameraDevice(camera_name, 1, save_name)
def __init__(self, camera_option: int, width: int, height: int) -> None:
Copy link
Member

Choose a reason for hiding this comment

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

Make camera_option the enum

self.device = camera_factory.create_camera(camera_option, width, height)

def run(self) -> "tuple[bool, image_and_time.ImageAndTime | None]":
"""
Returns a possible ImageAndTime with current timestamp.
"""
result, image = self.device.get_image()
result, image = self.device.run()
if not result:
return False, None

Expand Down
8 changes: 5 additions & 3 deletions modules/video_input/video_input_worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
def video_input_worker(
camera_name: "int | str",
Copy link
Member

Choose a reason for hiding this comment

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

This should be the CameraOption enum class. Then, you will need to change the config.yaml to include this option. You will also need to change the config loading portion of the code (similar to DETECT_TARGET_OPTION_INT).

period: float,
save_name: str,
width: int,
height: int,
output_queue: queue_proxy_wrapper.QueueProxyWrapper,
controller: worker_controller.WorkerController,
) -> None:
Expand All @@ -21,11 +22,12 @@ def video_input_worker(

camera_name is initial setting.
period is minimum period between loops.
save_name is path for logging.
width is the width of the images the camera takes in pixels
height is the height of the images the camera takes in pixelss
output_queue is the data queue.
controller is how the main process communicates to this worker process.
"""
input_device = video_input.VideoInput(camera_name, save_name)
input_device = video_input.VideoInput(camera_name, width, height)

while not controller.is_exit_requested():
controller.check_pause()
Expand Down
6 changes: 3 additions & 3 deletions tests/integration/test_video_input_hardware.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@


CAMERA = 0
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 rename this to camera option? Also, isn't there an enum for what each number means? Please use the enum

WIDTH = 1920
HEIGHT = 1080


def main() -> int:
Expand All @@ -14,9 +16,7 @@ def main() -> int:
"""
# Setup
# TODO: Common change logging option
camera = video_input.VideoInput(
CAMERA,
)
camera = video_input.VideoInput(CAMERA, WIDTH, HEIGHT)

# Run
result, image = camera.run()
Expand Down
Loading