-
Notifications
You must be signed in to change notification settings - Fork 37
integrated camera_factory in video_input #232
Changes from 5 commits
752233d
38ba0d8
fd79964
e4afb45
4533f3a
b6de157
8ddc188
e7f966c
a1d9238
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,30 +2,56 @@ | |
| Gets images from the camera. | ||
| """ | ||
|
|
||
| import os | ||
| import pathlib | ||
| import time | ||
|
|
||
| from utilities.workers import queue_proxy_wrapper | ||
| from utilities.workers import worker_controller | ||
| from . import video_input | ||
| from ..common.modules.camera import camera_factory | ||
| from ..common.modules.camera import camera_opencv | ||
| from ..common.modules.camera import camera_picamera2 | ||
| from ..common.modules.logger import logger | ||
|
|
||
|
|
||
| def video_input_worker( | ||
| camera_name: "int | str", | ||
| period: float, | ||
| save_name: str, | ||
| period: int, | ||
|
||
| camera_option: camera_factory.CameraOption, | ||
| width: int, | ||
| height: int, | ||
| camera_config: camera_opencv.ConfigOpenCV | camera_picamera2.ConfigPiCamera2, | ||
| save_prefix: str, | ||
| output_queue: queue_proxy_wrapper.QueueProxyWrapper, | ||
| controller: worker_controller.WorkerController, | ||
| ) -> None: | ||
| """ | ||
| Worker process. | ||
| camera_name is initial setting. | ||
| period is minimum period between loops. | ||
| save_name is path for logging. | ||
| period is the minimum period between image captures. | ||
Xierumeng marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| 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) | ||
| worker_name = pathlib.Path(__file__).stem | ||
| process_id = os.getpid() | ||
| result, local_logger = logger.Logger.create(f"{worker_name}_{process_id}", True) | ||
| if not result: | ||
| print("ERROR: Worker failed to create logger") | ||
| return | ||
|
|
||
| assert local_logger is not None | ||
|
|
||
| local_logger.info("Logger initialized") | ||
|
|
||
| result, input_device = video_input.VideoInput.create( | ||
| camera_option, width, height, camera_config, save_prefix, local_logger | ||
| ) | ||
| if not result: | ||
| local_logger.error("Worker failed to create class object") | ||
| return | ||
|
|
||
| # Get Pylance to stop complaining | ||
| assert input_device is not None | ||
|
|
||
| while not controller.is_exit_requested(): | ||
| controller.check_pause() | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,21 +2,38 @@ | |
| Simple hardware test, requires camera. | ||
| """ | ||
|
|
||
| import pathlib | ||
|
|
||
| from modules.common.modules.camera import camera_factory | ||
| from modules.common.modules.camera import camera_opencv | ||
| from modules.common.modules.logger import logger | ||
| from modules.video_input import video_input | ||
|
|
||
|
|
||
| CAMERA = 0 | ||
| # Modify as needed | ||
| CAMERA = camera_factory.CameraOption.OPENCV | ||
| WIDTH = 1920 | ||
| HEIGHT = 1200 | ||
|
||
| CONFIG = camera_opencv.ConfigOpenCV(0) | ||
| SAVE_PREFIX = "" # Not saving any pictures | ||
|
|
||
|
|
||
| def main() -> int: | ||
| """ | ||
| Main function. | ||
| """ | ||
| # Logger | ||
| test_name = pathlib.Path(__file__).stem | ||
| result, local_logger = logger.Logger.create(test_name, False) | ||
| assert result | ||
| assert local_logger is not None | ||
|
|
||
| # Setup | ||
| # TODO: Common change logging option | ||
| camera = video_input.VideoInput( | ||
| CAMERA, | ||
| result, camera = video_input.VideoInput.create( | ||
| CAMERA, WIDTH, HEIGHT, CONFIG, SAVE_PREFIX, local_logger | ||
| ) | ||
| assert result | ||
| assert camera is not None | ||
|
|
||
| # Run | ||
| result, image = camera.run() | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,14 +6,21 @@ | |
| import queue | ||
| import time | ||
|
|
||
| from modules.common.modules.camera import camera_factory | ||
| from modules.common.modules.camera import camera_opencv | ||
| from modules.video_input import video_input_worker | ||
| from modules import image_and_time | ||
| from utilities.workers import queue_proxy_wrapper | ||
| from utilities.workers import worker_controller | ||
|
|
||
|
|
||
| # Modify these settings as needed | ||
| VIDEO_INPUT_WORKER_PERIOD = 1.0 | ||
| CAMERA = 0 | ||
| CAMERA = camera_factory.CameraOption.OPENCV | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also failing here, but for some reason there is a conversion which results in this being |
||
| WIDTH = 1920 | ||
| HEIGHT = 1200 | ||
| CONFIG = camera_opencv.ConfigOpenCV(0) | ||
| SAVE_PREFIX = "" # Not saving any pictures | ||
|
|
||
|
|
||
| def main() -> int: | ||
|
|
@@ -29,7 +36,16 @@ def main() -> int: | |
|
|
||
| worker = mp.Process( | ||
| target=video_input_worker.video_input_worker, | ||
| args=(CAMERA, VIDEO_INPUT_WORKER_PERIOD, "", out_queue, controller), | ||
| args=( | ||
| VIDEO_INPUT_WORKER_PERIOD, | ||
| CAMERA, | ||
| WIDTH, | ||
| HEIGHT, | ||
| CONFIG, | ||
| SAVE_PREFIX, | ||
| out_queue, | ||
| controller, | ||
| ), | ||
| ) | ||
|
|
||
| # Run | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.