From da490fdfcd98f0cfb31fe601d37c5139705200ff Mon Sep 17 00:00:00 2001 From: Joel Collins Date: Wed, 28 Oct 2020 15:40:29 +0000 Subject: [PATCH 1/4] Separated move_and_measure locks --- openflexure_microscope/api/default_extensions/autofocus.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/openflexure_microscope/api/default_extensions/autofocus.py b/openflexure_microscope/api/default_extensions/autofocus.py index 089eae4c..507a9fac 100644 --- a/openflexure_microscope/api/default_extensions/autofocus.py +++ b/openflexure_microscope/api/default_extensions/autofocus.py @@ -325,7 +325,7 @@ class MoveAndMeasureAPI(ActionView): if microscope.has_real_stage(): # Acquire microscope lock with 1s timeout - with microscope.lock(timeout=1): + with microscope.camera.lock, microscope.stage.lock: return move_and_measure(microscope, dz=args.get("dz")) else: From 3cfbb40655b0ce00e3efd25be50a6107bccdec2a Mon Sep 17 00:00:00 2001 From: Joel Collins Date: Wed, 28 Oct 2020 15:40:51 +0000 Subject: [PATCH 2/4] Removed pointless GPU preview log --- openflexure_microscope/camera/pi.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/openflexure_microscope/camera/pi.py b/openflexure_microscope/camera/pi.py index 65fd8c35..5881acdd 100644 --- a/openflexure_microscope/camera/pi.py +++ b/openflexure_microscope/camera/pi.py @@ -315,8 +315,6 @@ class PiCameraStreamer(BaseCamera): def start_preview(self, fullscreen=True, window=None): """Start the on board GPU camera preview.""" - logging.info("Starting the GPU preview") - with self.lock(): try: if not self.camera.preview: From 32ec2b463dd3db8f16df74f11b7a0524c446aec9 Mon Sep 17 00:00:00 2001 From: Joel Collins Date: Wed, 28 Oct 2020 15:41:06 +0000 Subject: [PATCH 3/4] Fixed thumbnail data fallback --- openflexure_microscope/captures/capture.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/openflexure_microscope/captures/capture.py b/openflexure_microscope/captures/capture.py index ecee9462..5c840454 100644 --- a/openflexure_microscope/captures/capture.py +++ b/openflexure_microscope/captures/capture.py @@ -348,7 +348,7 @@ class CaptureObject(object): if thumbnail: return io.BytesIO(thumbnail) # If no thumbnail exists, serve the full image - return self.data.getvalue() + return self.data def save(self) -> None: """Write stream to file, and save/update metadata file""" From 1f12154876c4962616d6f179ab9af4ad1b95e599 Mon Sep 17 00:00:00 2001 From: Joel Collins Date: Wed, 28 Oct 2020 16:02:08 +0000 Subject: [PATCH 4/4] Fixed thumbnail generation for video_port captures --- openflexure_microscope/captures/__init__.py | 2 +- openflexure_microscope/captures/capture.py | 14 ++++++++++++-- openflexure_microscope/microscope.py | 4 ++-- 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/openflexure_microscope/captures/__init__.py b/openflexure_microscope/captures/__init__.py index 3b7e84d6..4df0ac64 100644 --- a/openflexure_microscope/captures/__init__.py +++ b/openflexure_microscope/captures/__init__.py @@ -1,3 +1,3 @@ from . import capture, capture_manager -from .capture import CaptureObject +from .capture import CaptureObject, THUMBNAIL_SIZE from .capture_manager import CaptureManager diff --git a/openflexure_microscope/captures/capture.py b/openflexure_microscope/captures/capture.py index 5c840454..787572fa 100644 --- a/openflexure_microscope/captures/capture.py +++ b/openflexure_microscope/captures/capture.py @@ -6,6 +6,7 @@ import logging import os import uuid from collections import OrderedDict +from PIL import Image import dateutil.parser @@ -14,6 +15,7 @@ from openflexure_microscope.camera.piexif._exceptions import InvalidImageDataErr from openflexure_microscope.config import JSONEncoder EXIF_FORMATS = ["JPG", "JPEG", "TIF", "TIFF"] +THUMBNAIL_SIZE = (200, 150) def pull_usercomment_dict(filepath): @@ -347,8 +349,16 @@ class CaptureObject(object): thumbnail = exif_dict.pop("thumbnail") if thumbnail: return io.BytesIO(thumbnail) - # If no thumbnail exists, serve the full image - return self.data + # If no thumbnail exists, make and save one + thumb_bytes = io.BytesIO() + thumb_im = Image.open(self.data) + thumb_im.thumbnail(THUMBNAIL_SIZE) + thumb_im.save(thumb_bytes, "jpeg") + thumbnail = thumb_bytes.getvalue() + exif_dict["thumbnail"] = thumbnail + exif_bytes = piexif.dump(exif_dict) + piexif.insert(exif_bytes, self.file) + return io.BytesIO(thumbnail) def save(self) -> None: """Write stream to file, and save/update metadata file""" diff --git a/openflexure_microscope/microscope.py b/openflexure_microscope/microscope.py index 1cbcf270..6e5b9bff 100644 --- a/openflexure_microscope/microscope.py +++ b/openflexure_microscope/microscope.py @@ -10,7 +10,7 @@ import pkg_resources from expiringdict import ExpiringDict from openflexure_microscope.camera.mock import MissingCamera -from openflexure_microscope.captures import CaptureManager +from openflexure_microscope.captures import CaptureManager, THUMBNAIL_SIZE from openflexure_microscope.stage.mock import MissingStage from openflexure_microscope.stage.sanga import SangaDeltaStage, SangaStage @@ -387,7 +387,7 @@ class Microscope: # Capture to output object extras = {} if fmt == "jpeg": - extras["thumbnail"] = (200, 150, 85) + extras["thumbnail"] = (*THUMBNAIL_SIZE, 85) logging.info("Starting microscope capture %s", output.file) self.camera.capture( output,