Swap stream for scan, target_resolution as arg
This commit is contained in:
parent
f5c1ff2621
commit
9f2a131f1e
4 changed files with 27 additions and 42 deletions
|
|
@ -294,7 +294,7 @@ class AutofocusThing(Thing):
|
||||||
capture: CaptureDep,
|
capture: CaptureDep,
|
||||||
images_dir: str,
|
images_dir: str,
|
||||||
stack_dir: str,
|
stack_dir: str,
|
||||||
capture_method: str = "array",
|
target_resolution: tuple[int, int],
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Run a z stack, saving all images to stack_dir and copying the
|
"""Run a z stack, saving all images to stack_dir and copying the
|
||||||
central image to stack_dir"""
|
central image to stack_dir"""
|
||||||
|
|
@ -311,21 +311,13 @@ class AutofocusThing(Thing):
|
||||||
stack_dir,
|
stack_dir,
|
||||||
f"{capture_count}.jpeg",
|
f"{capture_count}.jpeg",
|
||||||
)
|
)
|
||||||
if capture_method == "blob":
|
capture._capture_and_save(
|
||||||
capture.capture_jpeg(filename=jpeg_path, cam=cam)
|
jpeg_path=jpeg_path,
|
||||||
elif capture_method == "hires_array" or capture_method == "array":
|
cam=cam,
|
||||||
stream = "main" if capture_method == "array" else "full"
|
logger=logger,
|
||||||
capture._capture_and_save(
|
metadata_getter=metadata_getter,
|
||||||
jpeg_path=jpeg_path,
|
target_resolution=target_resolution,
|
||||||
cam=cam,
|
)
|
||||||
logger=logger,
|
|
||||||
metadata_getter=metadata_getter,
|
|
||||||
stream_name=stream,
|
|
||||||
)
|
|
||||||
else:
|
|
||||||
raise ValueError(
|
|
||||||
'Capture method must be one of "array", "blob" or "hires_array"'
|
|
||||||
)
|
|
||||||
|
|
||||||
# If the stack isn't complete yet, move
|
# If the stack isn't complete yet, move
|
||||||
if capture_count + 1 < images_to_capture:
|
if capture_count + 1 < images_to_capture:
|
||||||
|
|
|
||||||
|
|
@ -79,14 +79,9 @@ class CameraProtocol(Protocol):
|
||||||
"""Acquire one image from the preview stream and return its size"""
|
"""Acquire one image from the preview stream and return its size"""
|
||||||
...
|
...
|
||||||
|
|
||||||
def start_highres_streaming(self) -> None:
|
def start_streaming(self, main_resolution) -> None:
|
||||||
"""Start (or stop and restart) the camera in a configuration for low
|
"""Start (or stop and restart) the camera with the given resolution
|
||||||
res streaming and instant high res captures"""
|
for the main stream"""
|
||||||
...
|
|
||||||
|
|
||||||
def start_streaming(self) -> None:
|
|
||||||
"""Start (or stop and restart) the camera in the default streaming
|
|
||||||
configuration which balances stream and capture quality"""
|
|
||||||
...
|
...
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -194,15 +189,9 @@ class CameraStub(BaseCamera):
|
||||||
raise NotImplementedError("Cameras must not inherit from CameraStub")
|
raise NotImplementedError("Cameras must not inherit from CameraStub")
|
||||||
|
|
||||||
@thing_action
|
@thing_action
|
||||||
def start_highres_streaming(self):
|
def start_streaming(self, main_resolution) -> None:
|
||||||
"""Start (or stop and restart) the camera in a configuration for low
|
"""Start (or stop and restart) the camera with the given resolution
|
||||||
res streaming and instant high res captures"""
|
for the main stream"""
|
||||||
raise NotImplementedError("Cameras must not inherit from CameraStub")
|
|
||||||
|
|
||||||
@thing_action
|
|
||||||
def start_streaming(self) -> None:
|
|
||||||
"""Start (or stop and restart) the camera in the default streaming
|
|
||||||
configuration which balances stream and capture quality"""
|
|
||||||
raise NotImplementedError("Cameras must not inherit from CameraStub")
|
raise NotImplementedError("Cameras must not inherit from CameraStub")
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -28,7 +28,7 @@ class CaptureThing(Thing):
|
||||||
cam: CamDep,
|
cam: CamDep,
|
||||||
logger: InvocationLogger,
|
logger: InvocationLogger,
|
||||||
metadata_getter: GetThingStates,
|
metadata_getter: GetThingStates,
|
||||||
stream_name: str = "main",
|
target_resolution: tuple[int, int],
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Capture an image and save it to disk
|
"""Capture an image and save it to disk
|
||||||
|
|
||||||
|
|
@ -39,7 +39,7 @@ class CaptureThing(Thing):
|
||||||
image, metadata = self._capture_array(
|
image, metadata = self._capture_array(
|
||||||
cam,
|
cam,
|
||||||
metadata_getter,
|
metadata_getter,
|
||||||
stream=stream_name,
|
target_resolution=target_resolution,
|
||||||
logger=logger,
|
logger=logger,
|
||||||
)
|
)
|
||||||
acquisition_time = time.time()
|
acquisition_time = time.time()
|
||||||
|
|
@ -81,7 +81,7 @@ class CaptureThing(Thing):
|
||||||
cam: CamDep,
|
cam: CamDep,
|
||||||
metadata_getter: GetThingStates,
|
metadata_getter: GetThingStates,
|
||||||
logger: InvocationLogger,
|
logger: InvocationLogger,
|
||||||
stream: str = "main",
|
target_resolution: tuple[int, int] = (1640, 1232),
|
||||||
):
|
):
|
||||||
"""Capture an image in memory and return it with metadata
|
"""Capture an image in memory and return it with metadata
|
||||||
CaptureError raised if the capture fails for any reason
|
CaptureError raised if the capture fails for any reason
|
||||||
|
|
@ -90,7 +90,13 @@ class CaptureThing(Thing):
|
||||||
for capture_attempts in range(5):
|
for capture_attempts in range(5):
|
||||||
try:
|
try:
|
||||||
metadata = metadata_getter()
|
metadata = metadata_getter()
|
||||||
image = cam.capture_array(stream_name=stream, wait=5)[..., :3]
|
image = Image.fromarray(
|
||||||
|
cam.capture_array(stream_name="main", wait=5)[..., :3].astype(
|
||||||
|
"uint8"
|
||||||
|
),
|
||||||
|
"RGB",
|
||||||
|
)
|
||||||
|
image = image.resize(target_resolution, Image.LANCZOS)
|
||||||
return image, metadata
|
return image, metadata
|
||||||
except TimeoutError:
|
except TimeoutError:
|
||||||
logger.warning(
|
logger.warning(
|
||||||
|
|
@ -110,9 +116,7 @@ class CaptureThing(Thing):
|
||||||
IOError is raised if the file cannot be saved
|
IOError is raised if the file cannot be saved
|
||||||
nothing is returned on success"""
|
nothing is returned on success"""
|
||||||
try:
|
try:
|
||||||
Image.fromarray(image.astype("uint8"), "RGB").save(
|
image.save(jpeg_path, quality=95, subsampling=0)
|
||||||
jpeg_path, quality=95, subsampling=0
|
|
||||||
)
|
|
||||||
try:
|
try:
|
||||||
exif_dict = piexif.load(jpeg_path)
|
exif_dict = piexif.load(jpeg_path)
|
||||||
exif_dict["Exif"][piexif.ExifIFD.UserComment] = json.dumps(
|
exif_dict["Exif"][piexif.ExifIFD.UserComment] = json.dumps(
|
||||||
|
|
|
||||||
|
|
@ -182,7 +182,7 @@ class SmartScanThing(Thing):
|
||||||
self._scan_images_taken = 0
|
self._scan_images_taken = 0
|
||||||
self._stitch_resize = 1
|
self._stitch_resize = 1
|
||||||
|
|
||||||
self._cam.start_highres_streaming()
|
self._cam.start_streaming(main_resolution=(3280, 2464))
|
||||||
|
|
||||||
# Don't set self._scan_data dictionary. This is done at the start of _run_scan
|
# Don't set self._scan_data dictionary. This is done at the start of _run_scan
|
||||||
|
|
||||||
|
|
@ -692,7 +692,7 @@ class SmartScanThing(Thing):
|
||||||
self._autofocus.run_z_stack(
|
self._autofocus.run_z_stack(
|
||||||
images_dir=self._ongoing_scan_images_dir,
|
images_dir=self._ongoing_scan_images_dir,
|
||||||
stack_dir=site_folder,
|
stack_dir=site_folder,
|
||||||
capture_method="blob",
|
target_resolution=(1640, 1232),
|
||||||
)
|
)
|
||||||
|
|
||||||
# increment capure counter as thread has completed
|
# increment capure counter as thread has completed
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue