Assorted type fixes

This commit is contained in:
Julian Stirling 2025-12-17 21:50:31 +00:00
parent 472aa03822
commit 4060c06a2b
8 changed files with 41 additions and 44 deletions

View file

@ -204,7 +204,7 @@ class BaseCamera(lt.Thing):
@lt.action
def start_streaming(
self, main_resolution: tuple[int, int], buffer_count: int
self, main_resolution: tuple[int, int] = (800, 800), buffer_count: int = 1
) -> None:
"""Start (or stop and restart) the camera.
@ -364,7 +364,7 @@ class BaseCamera(lt.Thing):
self,
stream_name: Literal["main", "lores", "raw"],
wait: Optional[float] = None,
) -> Image:
) -> Image.Image:
"""Capture a PIL image from stream stream_name with timeout wait."""
raise NotImplementedError(
"CameraThings must define their own capture_image method"
@ -431,7 +431,7 @@ class BaseCamera(lt.Thing):
"""Clear all images in memory."""
self._memory_buffer.clear()
def _robust_image_capture(self) -> Tuple[Image, Mapping[str, Any]]:
def _robust_image_capture(self) -> Tuple[Image.Image, Mapping[str, Any]]:
"""Capture an image in memory and return it with metadata.
This robust capturing method attempts to capture the image five times
@ -513,7 +513,7 @@ class BaseCamera(lt.Thing):
def _save_capture(
self,
jpeg_path: str,
image: Image,
image: Image.Image,
metadata: dict,
save_resolution: Optional[Tuple[int, int]] = None,
) -> None:

View file

@ -113,7 +113,7 @@ class OpenCVCamera(BaseCamera):
self,
stream_name: Literal["main", "full"] = "main",
wait: Optional[float] = None,
) -> Image:
) -> Image.Image:
"""Acquire one image from the camera and return as a PIL image.
This function will produce a JPEG image.

View file

@ -534,7 +534,7 @@ class StreamingPiCamera2(BaseCamera):
self,
stream_name: Literal["main", "lores", "full"] = "main",
wait: Optional[float] = 0.9,
) -> Image:
) -> Image.Image:
"""Acquire one image from the camera and return it as a PIL Image.
If the ``stream_name`` parameter is ``main`` or ``lores``, it will be captured

View file

@ -196,7 +196,7 @@ class SimulatedCamera(BaseCamera):
self.canvas[top:bottom, left:right] -= sprite
def generate_image(self, pos: tuple[int, int, int]) -> Image:
def generate_image(self, pos: tuple[int, int, int]) -> Image.Image:
"""Generate an image with blobs based on supplied coordinates.
:param pos: a 3-item tuple containing the x,y,z coordinates of the 'stage'
@ -230,7 +230,7 @@ class SimulatedCamera(BaseCamera):
image[image > 255] = 255
return Image.fromarray(image.astype("uint8"))
def generate_frame(self) -> Image:
def generate_frame(self) -> Image.Image:
"""Generate a frame with blobs based on the stage coordinates."""
try:
pos = self._stage.instantaneous_position
@ -337,7 +337,7 @@ class SimulatedCamera(BaseCamera):
self,
stream_name: Literal["main", "lores", "raw"],
wait: Optional[float] = None,
) -> Image:
) -> Image.Image:
"""Capture to a PIL image. This is not exposed as a ThingAction.
It is used for capture to memory.
@ -403,7 +403,7 @@ class SimulatedCamera(BaseCamera):
return [property_control_for(self, "noise_level", label="Noise Level")]
def _frame2bytes(frame: Image) -> bytes:
def _frame2bytes(frame: Image.Image) -> bytes:
"""Convert frame to bytes."""
with io.BytesIO() as buf:
# Save in low quality for speed.