From 673fbfc50721a06fb828e959ddc8347254eaeab3 Mon Sep 17 00:00:00 2001 From: Samuel Date: Fri, 27 Dec 2024 09:22:12 +0000 Subject: [PATCH] Put the camera in dark mode for a moment to catch property setting errors --- marimapper/camera.py | 2 +- marimapper/detector.py | 6 +++++- marimapper/detector_process.py | 4 ++++ marimapper/sfm.py | 4 +++- 4 files changed, 13 insertions(+), 3 deletions(-) diff --git a/marimapper/camera.py b/marimapper/camera.py index 6000616..0c9c9c5 100644 --- a/marimapper/camera.py +++ b/marimapper/camera.py @@ -86,7 +86,7 @@ def set_exposure(self, exposure): logger.debug(f"Setting exposure to {exposure}") if not self.device.set(cv2.CAP_PROP_EXPOSURE, exposure): - logger.warning(f"Failed to set exposure to {exposure}") + logger.info(f"Failed to set exposure to {exposure}") def eat(self, count=30): for _ in range(count): diff --git a/marimapper/detector.py b/marimapper/detector.py index 785090b..8c32dfd 100644 --- a/marimapper/detector.py +++ b/marimapper/detector.py @@ -105,7 +105,11 @@ def set_cam_dark(cam: Camera, exposure: int) -> None: cam.set_autofocus(0, 0) cam.set_exposure_mode(0) cam.set_gain(0) - cam.set_exposure(exposure) + if not cam.set_exposure(exposure): + logger.warning( + f"failed to set exposure to {exposure}, your camera might not support exposure control, try darkening the scene and adjusting the threshold with --threshold " + ) + cam.eat() diff --git a/marimapper/detector_process.py b/marimapper/detector_process.py index 49a00da..eba79f2 100644 --- a/marimapper/detector_process.py +++ b/marimapper/detector_process.py @@ -72,6 +72,10 @@ def run(self): timeout_controller = TimeoutController() + # we quickly switch to dark mode here to throw any exceptions about the camera early + set_cam_dark(cam, self._dark_exposure) + set_cam_default(cam) + while not self._exit_event.is_set(): if not self._request_detections_queue.empty(): diff --git a/marimapper/sfm.py b/marimapper/sfm.py index ba4d06a..c380939 100644 --- a/marimapper/sfm.py +++ b/marimapper/sfm.py @@ -56,7 +56,9 @@ def sfm(leds_2d: list[LED2D]) -> list[LED3D]: new_map = binary_to_led_map_3d(Path(temp_dir)) - logger.debug(f"sfm managed to reconstruct {len(new_map)} leds in map {map_id}") + logger.debug( + f"sfm managed to reconstruct {len(new_map)} leds in map {map_id}" + ) leds_3d = new_map if len(new_map) > len(leds_3d) else leds_3d