Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 12 additions & 6 deletions src/labthings_picamera2/thing.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import tempfile
import time
from tempfile import TemporaryDirectory
import uuid

from pydantic import BaseModel, BeforeValidator, RootModel

Expand Down Expand Up @@ -529,7 +528,7 @@ def snap_image(self) -> ArrayModel:
def capture_array(
self,
stream_name: Literal["main", "lores", "raw"] = "main",
wait: Optional[float] = None,
wait: float = None,
) -> ArrayModel:
"""Acquire one image from the camera and return as an array

Expand All @@ -549,19 +548,22 @@ def capture_raw(
states_getter: GetThingStates,
get_states: bool=True,
get_processing_inputs: bool=True,
wait: float=None,
) -> RawImageModel:
"""Capture a raw image

This function is intended to be as fast as possible, and will return
as soon as an image has been captured. The output format is not intended
to be useful, except as input to `raw_to_png`.


wait: (Optional, float) Set a timeout in seconds. A TimeoutError is raised if this time is exceeded during capture. Default = None

When used via the HTTP interface, this function returns the data as a
`Blob` object, meaning it can be passed to another action without
transferring it over the network.
"""
with self.picamera() as cam:
(buffer, ), parameters = cam.capture_buffers(["raw"])
(buffer, ), parameters = cam.capture_buffers(["raw"], wait=wait)
configuration = cam.camera_configuration()
return RawImageModel(
image_data = RawBlob.from_bytes(buffer.tobytes()),
Expand Down Expand Up @@ -703,6 +705,7 @@ def capture_jpeg(
self,
metadata_getter: GetThingStates,
resolution: Literal["lores", "main", "full"] = "main",
wait: float = None,
) -> JPEGBlob:
"""Acquire one image from the camera as a JPEG

Expand All @@ -716,6 +719,9 @@ def capture_jpeg(
MJPEG stream and reconfigure the camera to capture a full
resolution image.

wait: (Optional, float) Set a timeout in seconds.
A TimeoutError is raised if this time is exceeded during capture. Default = None

Note that this always uses the image processing pipeline - to
bypass this, you must use a raw capture.
"""
Expand All @@ -727,7 +733,7 @@ def capture_jpeg(
# to reconfigure for these
if resolution in ("lores", "main") and config[resolution]:
with self.picamera() as cam:
cam.capture_file(path, name=resolution, format="jpeg")
cam.capture_file(path, name=resolution, format="jpeg", wait=wait)
else:
if resolution != "full":
logging.warning(
Expand All @@ -738,7 +744,7 @@ def capture_jpeg(
cam.configure(cam.create_still_configuration())
cam.start()
logging.info("capturing")
cam.capture_file(path, name="main", format="jpeg")
cam.capture_file(path, name="main", format="jpeg", wait=wait)
logging.info("done")
# After the file is written, add metadata about the current Things
exif_dict = piexif.load(path)
Expand Down