base#

Threaded base class for real-time camera frame processors.

class mesofield.processors.base.FrameProcessor[source]#

Bases: object

Base class for per-frame, real-time processors.

Acquisition stays on the camera thread; compute runs on a daemon worker thread fed by a bounded queue (size 1, drop-oldest replace) so processing latency cannot stall the camera. Subclasses implement one method:

def compute(self, img, idx, ts) -> float | None: ...

Returning None skips emission for that frame. Otherwise the scalar is emitted on:

  • self.signals.data(value, ts) – psygnal; pushed onto the DataQueue / CSV logger when the processor is registered with DataManager.register_hardware_device().

  • self.valueUpdated(t, value)pyqtSignal(float, float); Qt’s cross-thread queued connection makes SerialWidget safe to drive from the worker thread.

__init__(name=None, camera=None, sampling_rate=0.0, plot=False, **kwargs)[source]#
Parameters:
  • name (Optional[str])

  • camera (Optional['DataProducer'])

  • sampling_rate (float)

  • plot (bool)

  • kwargs (Any)

Return type:

None

compute(img, idx, ts)[source]#

Subclass hook: return one scalar (or None) per frame.

Called on every frame the attached camera emits. Implementations should be fast — anything heavy will starve the camera buffer. Return None to skip emitting a sample for this frame.

Parameters:
  • img (Any) – Frame from the camera (typically a 2-D ndarray).

  • idx (Any) – Frame index assigned by the camera (monotonic).

  • ts (Any) – Device timestamp for the frame.

Returns:

A single float to be pushed to the data queue / plot, or None to skip this frame.

Return type:

float | None

status()[source]#

Snapshot of the per-run compute-load counters.

Return type:

Dict[str, Any]

attach(camera=None)[source]#

Attach to a camera’s signals.frame and start the worker.

camera defaults to whatever was passed at construction time (self.camera); callers building processors first and attaching later may pass it explicitly.

Parameters:

camera (Optional['DataProducer'])

Return type:

None