diff --git a/marimapper/detector.py b/marimapper/detector.py index 3acdffd..728530b 100644 --- a/marimapper/detector.py +++ b/marimapper/detector.py @@ -115,10 +115,12 @@ def set_cam_dark(cam: Camera, exposure: int) -> None: def find_led( - cam: Camera, threshold: int = 128, display: bool = True + cam: Camera, threshold: int = 128, display: bool = True, dark_frame=None ) -> Optional[Point2D]: image = cam.read() + if dark_frame is not None: + cv2.subtract(image, dark_frame, image) results = find_led_in_image(image, threshold) if display: @@ -138,8 +140,10 @@ def enable_and_find_led( display: bool = False, ) -> Optional[LED2D]: + dark_frame = cam.read() + # First wait for no leds to be visible - while find_led(cam, threshold, display) is not None: + while find_led(cam, threshold, display, dark_frame=dark_frame) is not None: pass # Set the led to on and start the clock @@ -152,7 +156,7 @@ def enable_and_find_led( while ( point is None and time.time() < response_time_start + timeout_controller.timeout ): - point = find_led(cam, threshold, display) + point = find_led(cam, threshold, display, dark_frame) led_backend.set_led(led_id, False) @@ -161,7 +165,7 @@ def enable_and_find_led( timeout_controller.add_response_time(time.time() - response_time_start) - while find_led(cam, threshold, display) is not None: + while find_led(cam, threshold, display, dark_frame=dark_frame) is not None: pass return LED2D(led_id, view_id, point) diff --git a/marimapper/detector_process.py b/marimapper/detector_process.py index eba79f2..5b70c8e 100644 --- a/marimapper/detector_process.py +++ b/marimapper/detector_process.py @@ -86,9 +86,13 @@ def run(self): # scan start here set_cam_dark(cam, self._dark_exposure) + dark_frame = cam.read() # Firstly, if there are leds visible, break out - if find_led(cam, self._threshold, self._display) is not None: + if ( + find_led(cam, self._threshold, self._display, dark_frame=dark_frame) + is not None + ): logger.error( "Detector process can detect an LED when no LEDs should be visible" )