Capture a jpeg to disk

This commit is contained in:
jaknapper 2025-04-28 14:01:14 +01:00 committed by Julian Stirling
parent d8878e40da
commit ab33de7ccd
3 changed files with 15 additions and 9 deletions

View file

@ -310,12 +310,7 @@ class AutofocusThing(Thing):
stack_dir, stack_dir,
f"{capture_count}.jpeg", f"{capture_count}.jpeg",
) )
capture._capture_and_save( capture.capture_jpeg(filename=jpeg_path, cam=cam)
jpeg_path=jpeg_path,
cam=cam,
logger=logger,
metadata_getter=metadata_getter,
)
# If the stack isn't complete yet, move # If the stack isn't complete yet, move
if capture_count + 1 < images_to_capture: if capture_count + 1 < images_to_capture:

View file

@ -35,7 +35,7 @@ class CaptureThing(Thing):
that the stage may be moved while it's saved. that the stage may be moved while it's saved.
""" """
capture_start = time.time() capture_start = time.time()
image, metadata = self._capture_image( image, metadata = self._capture_array(
cam, cam,
metadata_getter, metadata_getter,
) )
@ -48,14 +48,21 @@ class CaptureThing(Thing):
f"Acquired {jpeg_path} in {acquisition_duration}s then {saving_duration}s saving to disk" f"Acquired {jpeg_path} in {acquisition_duration}s then {saving_duration}s saving to disk"
) )
def _capture_image(self, cam, metadata_getter) -> tuple[np.ndarray, dict]: @thing_action
def capture_jpeg(self, filename: str, cam: CamDep):
"""Capture a JPEG (from a JPEGBlob) to disk"""
jpeg = cam.capture_jpeg(resolution="full")
jpeg.save(filename)
@thing_action
def _capture_array(self, cam: CamDep, metadata_getter: GetThingStates):
"""Capture an image in memory and return it with metadata """Capture an image in memory and return it with metadata
CaptureError raised if the capture fails for any reason CaptureError raised if the capture fails for any reason
returns tuple with numpy array of image data, and dict of metadata returns tuple with numpy array of image data, and dict of metadata
""" """
try: try:
metadata = metadata_getter() metadata = metadata_getter()
image = cam.capture_array()[..., :3] image = cam.capture_array(stream_name="main")[..., :3]
except Exception as e: except Exception as e:
raise CaptureError("An error occurred while capturing") from e raise CaptureError("An error occurred while capturing") from e
return image, metadata return image, metadata

View file

@ -988,6 +988,8 @@ class SmartScanThing(Thing):
"preview_stitch", "preview_stitch",
"--minimum_overlap", "--minimum_overlap",
f"{min_overlap}", f"{min_overlap}",
"--resize",
"0.25",
self._ongoing_scan_images_dir, self._ongoing_scan_images_dir,
] ]
) )
@ -1104,6 +1106,8 @@ class SmartScanThing(Thing):
"--stitch_dzi", "--stitch_dzi",
"--minimum_overlap", "--minimum_overlap",
f"{round(overlap * 0.9, 2)}", f"{round(overlap * 0.9, 2)}",
"--resize",
"0.25",
images_folder, images_folder,
], ],
) )