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

@ -17,7 +17,6 @@ from subprocess import SubprocessError
from fastapi import HTTPException
from fastapi.responses import FileResponse
import numpy as np
from PIL import Image
import labthings_fastapi as lt
@ -234,8 +233,7 @@ class SmartScanThing(lt.Thing):
:returns: (dx, dy) - the x and y displacements in steps
"""
test_jpg = self._cam.grab_jpeg()
test_image = np.array(Image.open(test_jpg.open()))
test_image = self._cam.grab_as_array()
test_image_res = list(test_image.shape)
csm_image_res = [int(i) for i in self._csm.image_resolution]