Skip to content

Commit

Permalink
fix: bug in config window when using Camera object returning None
Browse files Browse the repository at this point in the history
The error image indicating that no image could be grabbed was being displayed recurrently, whereas it should only be before the very first image is captured.

Fixes #113
  • Loading branch information
WeisLeDocto committed Mar 7, 2024
1 parent cf5b58e commit e099409
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/crappy/tool/camera_config/camera_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ def __init__(self,
self._run = True
self._n_loops = 0
self._max_freq = max_freq
self._got_first_img: bool = False

# Settings for adjusting the behavior of the zoom
self._zoom_ratio = 0.9
Expand Down Expand Up @@ -1025,13 +1026,12 @@ def _update_img(self) -> None:
ret = self._camera.get_image()

# Flag raised if no image could be grabbed
no_img = False
no_img = ret is None

# If no frame could be grabbed from the camera
if ret is None:
no_img = True
if no_img:
# If it's the first call, generate error image to initialize the window
if not self._n_loops:
if not self._got_first_img:
self.log(logging.WARNING, "Could not get an image from the camera, "
"displaying an error image instead")
ret = None, np.array(Image.open(BytesIO(resource_string(
Expand All @@ -1043,6 +1043,8 @@ def _update_img(self) -> None:
sleep(0.001)
return

# Always set, so that the error image is only ever loaded once
self._got_first_img = True
self._n_loops += 1
_, img = ret

Expand Down

0 comments on commit e099409

Please sign in to comment.