Provide an API endpoint for camera snapshots rather than relying on legacy.

This commit is contained in:
Julian Stirling 2026-06-21 13:41:29 +01:00
parent 9b12d5ca52
commit 4d5fd0b698
2 changed files with 23 additions and 5 deletions

View file

@ -20,6 +20,7 @@ from typing import Any, Literal, Mapping, Optional, Self
import numpy as np
import piexif
from fastapi import Response
from PIL import Image
from pydantic import BaseModel
@ -259,6 +260,21 @@ class BaseCamera(OFMThing, ABC):
"""Close hardware connection when the Thing context manager is closed."""
pass
@lt.endpoint(
"get",
"snapshot",
responses={
200: {
"description": "A snapshot of the microscope stream",
"content": {"image/jpeg": {}},
},
},
)
async def snapshot(self) -> Response:
"""Return a snapshot from the microscope."""
jpeg_data = await self.lores_mjpeg_stream.grab_frame()
return Response(content=jpeg_data, media_type="image/jpeg")
@property
def focus_fom(self) -> int:
"""Return the focus figure of merit.