examples: make StreamPipeline the recommended entry, archive the manual loop
The two canonical examples taught the advanced path: they sequenced get_img() -> compute_deformation() -> compute_contact() -> read_info() by hand and unpacked a 13-element tuple positionally, which is what led developers to reach for the compute backend, the capture queue and the stitch mode. The managed alternative already existed and was documented nowhere. Library (add-only, nothing removed): - FrameSnapshot.image_size_raw carries the capture resolution, so a caller can compare it with the processed frame instead of reaching into Sensor. - StreamPipeline.reset() resets the tracker and force filters *safely*. It is queued and applied by the flow stage before its next frame, never inline: Sensor.reset rebases initial_img on the current Sensor.img, which the flow stage is reading concurrently, so a caller-thread reset would capture a half-written reference frame. Idempotent. - TactileProcessor.pipeline(produce) and FingerRuntime.pipeline() build a pipeline without the caller naming a backend concept; the latter is `with runtime.pipeline(contact=True) as pipe`. Examples: - examples/basic_pipeline.py and examples/finger_pipeline.py rewritten onto StreamPipeline + FrameSnapshot: one object, one call per frame, no tuple, and no compute backend, queue or stitch setting in sight. - examples/archive/basic_pipeline_manual.py and _finger_pipeline_manual.py keep the previous versions byte-for-byte apart from a supersede header, so code copied from them keeps working. The finger header also records the archived --show defect (store_true with default=True, so it could never be disabled). - examples/_display.py holds the shared display helpers, so an example no longer hand-rolls depth normalisation and colormap application. - examples/README.md leads with the recommended pair and documents the manual form as still-supported, and states that examples/gui/ is moving to orisys-studio. Tests: three added to tests/test_pipeline.py, covering the reset queue (it must not run on the caller's thread and must land before the first compute_flow), image_size_raw, and the None case when a producer reports no size. Verified the reset test fails when reset() is made inline, so it discriminates. Verified end-to-end against real media: basic_pipeline on data/sample/s1_480p.mp4 (box) reaches ~113 FPS and exits 0; finger_pipeline on data/dd02-0703/1.mp4 (finger) reaches ~140 FPS with mask coverage 0.41 and exits 0. Both archived manual versions still run. tests/test_pipeline.py: 20 passed. Full suite: 342 passed, 3 failed - all three failures reproduce on the pristine tree (import precedence, longrun timing, and a stale ruff version literal in docs/code-review.md) and are unrelated to this change.
This commit is contained in:
@@ -114,6 +114,21 @@ class TactileProcessor:
|
||||
def warmup(self):
|
||||
return self._sensor.warmup_deformation()
|
||||
|
||||
def pipeline(self, produce, **kwargs):
|
||||
"""Start a :class:`~orisys.pipeline.StreamPipeline` over this processor's own Sensor.
|
||||
|
||||
``produce`` is the frame source: a zero-argument callable returning the next unrolled
|
||||
frame, or ``None`` at end of input. :class:`FingerRuntime` supplies it through
|
||||
:meth:`FingerRuntime.pipeline`, so call this directly only when you are producing frames
|
||||
yourself.
|
||||
|
||||
Any keyword argument is forwarded to ``StreamPipeline``, so ``contact=True`` and
|
||||
``include=(...)`` work exactly as they do there.
|
||||
"""
|
||||
from orisys.pipeline import StreamPipeline
|
||||
|
||||
return StreamPipeline(self._sensor, produce, **kwargs)
|
||||
|
||||
def compute_deformation(self, *args, **kwargs):
|
||||
return self._sensor.compute_deformation(*args, **kwargs)
|
||||
|
||||
@@ -361,6 +376,27 @@ class FingerRuntime:
|
||||
self.tactile.warmup()
|
||||
return ok, unrolled
|
||||
|
||||
def pipeline(self, **kwargs):
|
||||
"""Return a :class:`~orisys.pipeline.StreamPipeline` for this runtime.
|
||||
|
||||
The recommended way to run a finger sensor. Each finished frame arrives as a single
|
||||
:class:`~orisys.pipeline.FrameSnapshot`, so there are no stage calls to sequence and no
|
||||
tuple to unpack::
|
||||
|
||||
with runtime.pipeline(contact=True, include=("image", "depth")) as pipe:
|
||||
while True:
|
||||
snap = pipe.wait()
|
||||
if snap is None:
|
||||
break
|
||||
print(snap.normal_force, snap.shear_x, snap.shear_y)
|
||||
|
||||
Any keyword argument is forwarded to ``StreamPipeline``. Use ``contact=True`` to run
|
||||
contact analysis, and ``include=(...)`` to select which arrays each snapshot carries.
|
||||
"""
|
||||
from orisys.pipeline import StreamPipeline
|
||||
|
||||
return StreamPipeline.for_finger_runtime(self, **kwargs)
|
||||
|
||||
def close(self):
|
||||
if self.capture_source is not None:
|
||||
self.capture_source.close()
|
||||
|
||||
Reference in New Issue
Block a user