Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions marimapper/detector.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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
Expand All @@ -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)

Expand All @@ -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)
6 changes: 5 additions & 1 deletion marimapper/detector_process.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down
Loading