From a61ffbf75a147e6c0467460ed9e35ea23219d546 Mon Sep 17 00:00:00 2001 From: Richard Bowman Date: Mon, 5 Feb 2024 17:14:56 +0000 Subject: [PATCH] WIP: use code from labthings-picamera2 for EXIF writing I've now switched to using piexif to write the EXIF tag, which is slower - but still does not seem to work in openflexure- stitching. --- .../things/smart_scan.py | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/src/openflexure_microscope_server/things/smart_scan.py b/src/openflexure_microscope_server/things/smart_scan.py index 6b77bb82..30b7ae47 100644 --- a/src/openflexure_microscope_server/things/smart_scan.py +++ b/src/openflexure_microscope_server/things/smart_scan.py @@ -582,19 +582,17 @@ class SmartScanThing(Thing): processed = rggb2rgb(raw2rggb(raw_image)) / white_norm processed[processed > 255] = 255 processed[processed < 0] = 0 - img = Image.fromarray(processed, mode="RGB") + img = Image.fromarray(processed.astype(np.uint8), mode="RGB") img.save( os.path.join(images_folder, name), - exif=json.dumps( - { - "Exif": { - piexif.ExifIFD.UserComment: metadata_getter() - } - } - ).encode("utf-8"), quality=95, subsampling=0 ) + exif_dict = piexif.load(os.path.join(images_folder, name)) + exif_dict["Exif"][piexif.ExifIFD.UserComment] = json.dumps( + metadata_getter() + ).encode("utf-8") + piexif.insert(piexif.dump(exif_dict), os.path.join(images_folder, name)) save_time = time.time() logger.info(f"Acquired {name} in {acquisition_time-capture_start:.1f}s then {save_time-acquisition_time:.1f}s saving to disk") except Exception as e: