Add a grab_as_array camera method that grabs from the stream but catches broken jpegs and retries

This commit is contained in:
Julian Stirling 2025-08-20 19:05:29 +01:00
parent 347247f45b
commit 6fa4e4dc64
3 changed files with 47 additions and 10 deletions

View file

@ -52,7 +52,15 @@ def test_handle_broken_frame():
camera.mjpeg_stream.grab_frame = flaky_grabber
with camera_server(camera):
portal = lt.get_blocking_portal(camera)
# Check that this does cause broken frames.
with pytest.raises(OSError, match="broken data stream when reading image file"):
for _i in range(15):
jpeg = camera.grab_jpeg(portal)
np.asarray(Image.open(jpeg.open()))
# Check that grab_as_array handles the broken frames and completes without
# the same error.
for _i in range(15):
array = camera.grab_as_array(portal)
assert isinstance(array, np.ndarray)