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):
|
||||
"""
|
||||
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
|
||||
after they've been stored in a BytesIO stream,
|
||||
we tell the camera to write frames to this class instead.
|
||||
|
||||
We then do analysis as the frames are written, and discard the heavier
|
||||
image data.
|
||||
We then do analysis as the frames are written, and discard
|
||||
old frames as each new frame is written.
|
||||
"""
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
|
|
@ -39,16 +39,19 @@ class FrameStream(io.BytesIO):
|
|||
self.new_frame = ClientEvent()
|
||||
|
||||
def start_tracking(self):
|
||||
"""Start tracking frame sizes"""
|
||||
if not self.tracking:
|
||||
logging.debug("Started tracking frame data")
|
||||
self.tracking = True
|
||||
|
||||
def stop_tracking(self):
|
||||
"""Stop tracking frame sizes"""
|
||||
if self.tracking:
|
||||
logging.debug("Stopped tracking frame data")
|
||||
self.tracking = False
|
||||
|
||||
def reset_tracking(self):
|
||||
"""Empty the array of tracked frame sizes"""
|
||||
self.frames = []
|
||||
|
||||
def write(self, s):
|
||||
|
|
@ -72,9 +75,7 @@ class FrameStream(io.BytesIO):
|
|||
self.new_frame.set()
|
||||
|
||||
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()
|
||||
return super().getvalue()
|
||||
|
||||
|
|
@ -90,10 +91,9 @@ class BaseCamera(metaclass=ABCMeta):
|
|||
"""
|
||||
|
||||
def __init__(self):
|
||||
self.camera = None
|
||||
|
||||
#: :py:class:`labthings.StrictLock`: Access lock for the camera
|
||||
self.lock = StrictLock(name="Camera", timeout=None)
|
||||
|
||||
#: :py:class:`FrameStream`: Streaming and analysis frame buffer
|
||||
self.stream = FrameStream()
|
||||
|
||||
self.stream_active = False
|
||||
|
|
|
|||
|
|
@ -39,7 +39,6 @@ import picamerax
|
|||
import picamerax.array
|
||||
|
||||
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
|
||||
|
||||
# Richard's fix gain
|
||||
|
|
@ -76,10 +75,9 @@ class PiCameraStreamer(BaseCamera):
|
|||
def __init__(self):
|
||||
# Run BaseCamera init
|
||||
BaseCamera.__init__(self)
|
||||
# Attach to Pi camera
|
||||
self.camera = (
|
||||
picamerax.PiCamera()
|
||||
) #: :py:class:`picamerax.PiCamera`: Picamera object
|
||||
|
||||
#: :py:class:`picamerax.PiCamera`: Attached Picamera object
|
||||
self.camera = picamerax.PiCamera()
|
||||
|
||||
# Store state of PiCameraStreamer
|
||||
self.preview_active = False
|
||||
|
|
@ -87,18 +85,13 @@ class PiCameraStreamer(BaseCamera):
|
|||
# Reset variable states
|
||||
self.set_zoom(1.0)
|
||||
|
||||
# Set default settings
|
||||
self.image_resolution = tuple(
|
||||
self.camera.MAX_RESOLUTION
|
||||
) #: tuple: Resolution for image captures
|
||||
self.stream_resolution = (
|
||||
832,
|
||||
624,
|
||||
) #: tuple: Resolution for stream and video captures
|
||||
self.numpy_resolution = (
|
||||
1312,
|
||||
976,
|
||||
) #: tuple: Resolution for numpy array captures
|
||||
#: tuple: Resolution for image captures
|
||||
self.image_resolution = tuple(self.camera.MAX_RESOLUTION)
|
||||
#: tuple: Resolution for stream and video captures
|
||||
self.stream_resolution = (832, 624)
|
||||
#: tuple: Resolution for numpy array captures
|
||||
self.numpy_resolution = (1312, 976)
|
||||
|
||||
self.jpeg_quality = 100 #: int: JPEG quality
|
||||
self.mjpeg_quality = 75 #: int: MJPEG quality
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue