Cleaned up code layout
This commit is contained in:
parent
85f77fa867
commit
da6212616c
2 changed files with 19 additions and 26 deletions
|
|
@ -13,14 +13,14 @@ TrackerFrame = namedtuple("TrackerFrame", ["size", "time"])
|
||||||
|
|
||||||
class FrameStream(io.BytesIO):
|
class FrameStream(io.BytesIO):
|
||||||
"""
|
"""
|
||||||
A file-like object used to analyse MJPEG frames.
|
A file-like object used to analyse and stream MJPEG frames.
|
||||||
|
|
||||||
Instead of analysing a load of real MJPEG frames
|
Instead of analysing a load of real MJPEG frames
|
||||||
after they've been stored in a BytesIO stream,
|
after they've been stored in a BytesIO stream,
|
||||||
we tell the camera to write frames to this class instead.
|
we tell the camera to write frames to this class instead.
|
||||||
|
|
||||||
We then do analysis as the frames are written, and discard the heavier
|
We then do analysis as the frames are written, and discard
|
||||||
image data.
|
old frames as each new frame is written.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
|
|
@ -39,16 +39,19 @@ class FrameStream(io.BytesIO):
|
||||||
self.new_frame = ClientEvent()
|
self.new_frame = ClientEvent()
|
||||||
|
|
||||||
def start_tracking(self):
|
def start_tracking(self):
|
||||||
|
"""Start tracking frame sizes"""
|
||||||
if not self.tracking:
|
if not self.tracking:
|
||||||
logging.debug("Started tracking frame data")
|
logging.debug("Started tracking frame data")
|
||||||
self.tracking = True
|
self.tracking = True
|
||||||
|
|
||||||
def stop_tracking(self):
|
def stop_tracking(self):
|
||||||
|
"""Stop tracking frame sizes"""
|
||||||
if self.tracking:
|
if self.tracking:
|
||||||
logging.debug("Stopped tracking frame data")
|
logging.debug("Stopped tracking frame data")
|
||||||
self.tracking = False
|
self.tracking = False
|
||||||
|
|
||||||
def reset_tracking(self):
|
def reset_tracking(self):
|
||||||
|
"""Empty the array of tracked frame sizes"""
|
||||||
self.frames = []
|
self.frames = []
|
||||||
|
|
||||||
def write(self, s):
|
def write(self, s):
|
||||||
|
|
@ -72,9 +75,7 @@ class FrameStream(io.BytesIO):
|
||||||
self.new_frame.set()
|
self.new_frame.set()
|
||||||
|
|
||||||
def getvalue(self) -> bytes:
|
def getvalue(self) -> bytes:
|
||||||
"""
|
"""Clear tne new_frame event and return frame data"""
|
||||||
Clear tne new_frame event and return frame data
|
|
||||||
"""
|
|
||||||
self.new_frame.clear()
|
self.new_frame.clear()
|
||||||
return super().getvalue()
|
return super().getvalue()
|
||||||
|
|
||||||
|
|
@ -90,10 +91,9 @@ class BaseCamera(metaclass=ABCMeta):
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.camera = None
|
#: :py:class:`labthings.StrictLock`: Access lock for the camera
|
||||||
|
|
||||||
self.lock = StrictLock(name="Camera", timeout=None)
|
self.lock = StrictLock(name="Camera", timeout=None)
|
||||||
|
#: :py:class:`FrameStream`: Streaming and analysis frame buffer
|
||||||
self.stream = FrameStream()
|
self.stream = FrameStream()
|
||||||
|
|
||||||
self.stream_active = False
|
self.stream_active = False
|
||||||
|
|
|
||||||
|
|
@ -39,7 +39,6 @@ import picamerax
|
||||||
import picamerax.array
|
import picamerax.array
|
||||||
|
|
||||||
from openflexure_microscope.camera.base import BaseCamera
|
from openflexure_microscope.camera.base import BaseCamera
|
||||||
from openflexure_microscope.paths import settings_file_path
|
|
||||||
from openflexure_microscope.utilities import json_to_ndarray, ndarray_to_json
|
from openflexure_microscope.utilities import json_to_ndarray, ndarray_to_json
|
||||||
|
|
||||||
# Richard's fix gain
|
# Richard's fix gain
|
||||||
|
|
@ -76,10 +75,9 @@ class PiCameraStreamer(BaseCamera):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
# Run BaseCamera init
|
# Run BaseCamera init
|
||||||
BaseCamera.__init__(self)
|
BaseCamera.__init__(self)
|
||||||
# Attach to Pi camera
|
|
||||||
self.camera = (
|
#: :py:class:`picamerax.PiCamera`: Attached Picamera object
|
||||||
picamerax.PiCamera()
|
self.camera = picamerax.PiCamera()
|
||||||
) #: :py:class:`picamerax.PiCamera`: Picamera object
|
|
||||||
|
|
||||||
# Store state of PiCameraStreamer
|
# Store state of PiCameraStreamer
|
||||||
self.preview_active = False
|
self.preview_active = False
|
||||||
|
|
@ -87,18 +85,13 @@ class PiCameraStreamer(BaseCamera):
|
||||||
# Reset variable states
|
# Reset variable states
|
||||||
self.set_zoom(1.0)
|
self.set_zoom(1.0)
|
||||||
|
|
||||||
# Set default settings
|
#: tuple: Resolution for image captures
|
||||||
self.image_resolution = tuple(
|
self.image_resolution = tuple(self.camera.MAX_RESOLUTION)
|
||||||
self.camera.MAX_RESOLUTION
|
#: tuple: Resolution for stream and video captures
|
||||||
) #: tuple: Resolution for image captures
|
self.stream_resolution = (832, 624)
|
||||||
self.stream_resolution = (
|
#: tuple: Resolution for numpy array captures
|
||||||
832,
|
self.numpy_resolution = (1312, 976)
|
||||||
624,
|
|
||||||
) #: tuple: Resolution for stream and video captures
|
|
||||||
self.numpy_resolution = (
|
|
||||||
1312,
|
|
||||||
976,
|
|
||||||
) #: tuple: Resolution for numpy array captures
|
|
||||||
self.jpeg_quality = 100 #: int: JPEG quality
|
self.jpeg_quality = 100 #: int: JPEG quality
|
||||||
self.mjpeg_quality = 75 #: int: MJPEG quality
|
self.mjpeg_quality = 75 #: int: MJPEG quality
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue