pub struct SegmentSelector { /* private fields */ }Expand description
Segment the CONTINUOUS camera stream by print layer and pick the parked frame per layer
with select_park_frame — the dense-stream alternative to the sparse snapshot burst.
The native park runs at the LAYER CHANGE: a brief (~0.5 s) far-left dwell whose delay vs
the layer_num edge is large and WILDLY variable (it’s the layer-change gcode, so it
lands near the layer’s end relative to the edge, drifting with layer time). A sparse grid
of single grabs misses it, and so does a short fixed window after the edge — the very
failure that defeated the snapshot burst. The robust answer is to accumulate the WHOLE
layer (every frame until the next layer edge) and let the MEDIAN subtraction isolate the
transient far-left head against the layer’s typical printing frames. So window_ms is a
generous SAFETY CAP (max accumulation before forcing a selection, to bound memory if the
A1’s layer_num sticks), NOT a gate: in normal operation the next layer edge finalizes
the segment first, well within the cap. Feed gray frames as they arrive (their stream
idx, capture time, and the current layer); each layer’s frames accumulate until the next
layer (or the cap), then the selector runs over them and emits the chosen frame’s index.
Pure (no I/O): the caller owns ffmpeg + the ring JPEGs and copies the picked index out.
Implementations§
Source§impl SegmentSelector
impl SegmentSelector
pub fn new(w: usize, h: usize, window_ms: u64, cfg: SelectTuning) -> Self
Sourcepub fn push(
&mut self,
layer: i64,
idx: u64,
t_ms: u64,
gray: Vec<u8>,
) -> Option<SegmentPick>
pub fn push( &mut self, layer: i64, idx: u64, t_ms: u64, gray: Vec<u8>, ) -> Option<SegmentPick>
Feed one stream frame. Returns a SegmentPick when a layer’s window CLOSES with a
selected park — finalized either when the NEXT layer starts or window_ms elapses.
Frames after a layer’s window (until the next layer) are ignored. None otherwise.
Sourcepub fn finish(&mut self) -> Option<SegmentPick>
pub fn finish(&mut self) -> Option<SegmentPick>
Finalize the last open segment at stream end.