From ab33de7ccd569b4b4af5787ee9773c3177721f84 Mon Sep 17 00:00:00 2001 From: jaknapper Date: Mon, 28 Apr 2025 14:01:14 +0100 Subject: [PATCH] Capture a jpeg to disk --- .../things/autofocus.py | 7 +------ src/openflexure_microscope_server/things/capture.py | 13 ++++++++++--- .../things/smart_scan.py | 4 ++++ 3 files changed, 15 insertions(+), 9 deletions(-) diff --git a/src/openflexure_microscope_server/things/autofocus.py b/src/openflexure_microscope_server/things/autofocus.py index efcc7aca..45f43dcd 100644 --- a/src/openflexure_microscope_server/things/autofocus.py +++ b/src/openflexure_microscope_server/things/autofocus.py @@ -310,12 +310,7 @@ class AutofocusThing(Thing): stack_dir, f"{capture_count}.jpeg", ) - capture._capture_and_save( - jpeg_path=jpeg_path, - cam=cam, - logger=logger, - metadata_getter=metadata_getter, - ) + capture.capture_jpeg(filename=jpeg_path, cam=cam) # If the stack isn't complete yet, move if capture_count + 1 < images_to_capture: diff --git a/src/openflexure_microscope_server/things/capture.py b/src/openflexure_microscope_server/things/capture.py index 214c05b9..5c82da95 100644 --- a/src/openflexure_microscope_server/things/capture.py +++ b/src/openflexure_microscope_server/things/capture.py @@ -35,7 +35,7 @@ class CaptureThing(Thing): that the stage may be moved while it's saved. """ capture_start = time.time() - image, metadata = self._capture_image( + image, metadata = self._capture_array( cam, metadata_getter, ) @@ -48,14 +48,21 @@ class CaptureThing(Thing): 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 CaptureError raised if the capture fails for any reason returns tuple with numpy array of image data, and dict of metadata """ try: metadata = metadata_getter() - image = cam.capture_array()[..., :3] + image = cam.capture_array(stream_name="main")[..., :3] except Exception as e: raise CaptureError("An error occurred while capturing") from e return image, metadata diff --git a/src/openflexure_microscope_server/things/smart_scan.py b/src/openflexure_microscope_server/things/smart_scan.py index 50a8c442..f0d45d1d 100644 --- a/src/openflexure_microscope_server/things/smart_scan.py +++ b/src/openflexure_microscope_server/things/smart_scan.py @@ -988,6 +988,8 @@ class SmartScanThing(Thing): "preview_stitch", "--minimum_overlap", f"{min_overlap}", + "--resize", + "0.25", self._ongoing_scan_images_dir, ] ) @@ -1104,6 +1106,8 @@ class SmartScanThing(Thing): "--stitch_dzi", "--minimum_overlap", f"{round(overlap * 0.9, 2)}", + "--resize", + "0.25", images_folder, ], )