Handle passing a CaptureObject instance directly to capture()

This commit is contained in:
Joel Collins 2020-01-21 16:03:19 +00:00
parent e2f36d5e33
commit e6c4664cb8
2 changed files with 18 additions and 8 deletions

View file

@ -16,7 +16,7 @@ import logging
# Type hinting # Type hinting
from typing import Tuple from typing import Tuple
from openflexure_microscope.camera.base import BaseCamera from openflexure_microscope.camera.base import BaseCamera, CaptureObject
""" """
@ -189,14 +189,19 @@ class MockStreamer(BaseCamera):
bayer (bool): Store raw bayer data in capture bayer (bool): Store raw bayer data in capture
""" """
if isinstance(output, CaptureObject):
target = output.file
else:
target = target
with self.lock: with self.lock:
if isinstance(output, str): if isinstance(target, str):
output = open(output, "wb") target = open(target, "wb")
output.write(self.stream.getvalue()) target.write(self.stream.getvalue())
if isinstance(output, str): if isinstance(target, str):
output.close() target.close()
# HANDLE STREAM FRAMES # HANDLE STREAM FRAMES

View file

@ -548,6 +548,11 @@ class PiCameraStreamer(BaseCamera):
output_object (str/BytesIO): Target object. output_object (str/BytesIO): Target object.
""" """
if isinstance(output, CaptureObject):
target = output.file
else:
target = target
with self.lock: with self.lock:
logging.info("Capturing to {}".format(output)) logging.info("Capturing to {}".format(output))
@ -556,7 +561,7 @@ class PiCameraStreamer(BaseCamera):
self.stop_stream_recording() self.stop_stream_recording()
self.camera.capture( self.camera.capture(
output, target,
format=fmt, format=fmt,
quality=100, quality=100,
resize=resize, resize=resize,
@ -568,7 +573,7 @@ class PiCameraStreamer(BaseCamera):
if not use_video_port: if not use_video_port:
self.start_stream_recording() self.start_stream_recording()
return output return target
def yuv( def yuv(
self, use_video_port: bool = True, resize: Tuple[int, int] = None self, use_video_port: bool = True, resize: Tuple[int, int] = None