docs(omny): split vision plan into a generic toolkit/interface + confirm app
CI for csaxs_bec / test (push) Successful in 5m1s

Per feedback: split the design into three layers instead of one
confirm-scoring device. Layer 0 is a plain image-manipulation toolkit
(grayscale, edge detection, registration, overlays) with no device/BEC
dependency. Layer 1 is a new generic VisionInterface device -- camera in,
processed image out, mode selectable at runtime -- usable as an
in-between interface for any camera consumer, not just sample-transfer
confirms; x_ray_eye_align.py's alignment GUI is called out as a second,
independent consumer. Layer 2 (SampleVisionMonitor, the sample-transfer
confirm/scoring device from the previous pass) is now framed as one
application built on top of Layers 0/1.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018Mupip8x7Hean6E3FFvpbj
This commit is contained in:
x01dcandClaude Sonnet 5 committed 2026-09-06 13:15:11 +02:00
1 parent 9d4cd0347e
commit d04932b68d
1 file changed
+106 -53
@@ -15,8 +15,12 @@ Applied to BEC: could this let OMNY's sample-transfer flow (`otransfer_get_sampl
single one, while still catching real problems (pin damage, missed grip, wrong shuttle state)?
This doc maps that idea onto OMNY's actual confirm gates and camera/GUI plumbing, and proposes a
staged plan. **Goal for this session: write this plan down. Implementation is a separate, later
branch.**
staged plan. Follow-up feedback broadened the scope: rather than building the image-processing logic
into a single confirm/scoring device, keep it generic — a reusable camera-in/processed-image-out
interface (grayscale, edge detection, overlays, ...) that the sample-transfer confirm use case is
only the *first* consumer of; `x_ray_eye_align.py`'s alignment GUI is identified below as a second,
independent consumer of the same layer. **Goal for this session: write this plan down.
Implementation is a separate, later branch.**
## Where today's human confirmations actually live
@@ -80,56 +84,95 @@ post-hoc audit log today, with no comparison logic reading it back.
- **`opencv-python`** is already a project dependency (`pyproject.toml:27`); `scikit-image` is not
yet (needed only if SSIM specifically is wanted — see below).
## Proposed architecture: a generic, camera-agnostic vision device
## Proposed architecture: a generic, camera-agnostic vision layer
Earlier drafts of this plan sketched the CV pipeline as logic living inside `IDSCamera` itself, or
inline in `omny_sample_transfer_mixin.py` calling `cv2`/`skimage` directly against whichever
`cam200`-`cam203` frame it just pulled. Mirko's feedback: keep the imaging pipeline generic and
reusable against *any* camera, structured as its own device with a camera as a declared dependency,
rather than building it into a specific camera class. Concretely:
`cam200`-`cam203` frame it just pulled. Mirko's feedback, in two parts: (1) keep the imaging
pipeline generic and reusable against *any* camera, structured as its own device with a camera as a
declared dependency, rather than building it into a specific camera class; (2) go further than a
single-purpose confirm/scoring device — make the underlying image manipulation (grayscale, edge
detection, and similar) a generic, reusable *interface* that can sit between a raw camera and its
consumer for other purposes too, e.g. an alternative processed/overlay view for
`x_ray_eye_align.py`'s alignment GUI, not just sample-transfer scoring. Three layers, each usable on
its own:
- **A new, endstation-agnostic device class** (working name `SampleVisionMonitor`), living outside
`omny/` — e.g. `csaxs_bec/devices/vision/sample_vision_monitor.py` — so it isn't OMNY-specific
code, just OMNY's first user of it.
- **Its only hard dependency is the shared `get_last_image()` contract** above — nothing
`IDSCamera`-specific (no reliance on `push_smear_preview`, the `image` `PreviewSignal`'s
rotation/transpose handling, etc.). Any current or future camera class that implements
`get_last_image() -> np.ndarray | None` can be wired in, including `AlliedVisionAravisCamera` or a
simulated camera, with zero changes to this device.
- **Config-driven camera dependency, resolved lazily.** A `camera_names: list[str]` constructor
parameter (a list, not a single name, so OMNY's camera-*pairs* — `["cam200", "cam203"]` for
parking, `["cam201", "cam202"]` for the sample stage — are a natural fit; a single-camera setup
like flomni's gripper cam is just a length-1 list). Resolved through
`self.device_manager.devices.get(name, None)` at call time, mirroring `ddg_1.py`'s pattern above,
with a clear error if a configured name isn't present in the active session's device config.
**This is what makes the device reusable across endstations without touching its code**: the same
class, pointed at a different `camera_names` list in a different beamline's device-config YAML,
is the entire integration cost for a new camera or a new endstation.
- **Runs device-server-side** (a `PSIDeviceBase` subclass, like `IDSCamera` itself), consistent with
where camera image processing already happens in this codebase, and appropriate for the
registration/scoring compute cost.
- **Opaque, caller-defined reference tags**, not OMNY vocabulary baked into the device: reference
images and scores are grouped by a plain string tag the caller picks (for OMNY,
`f"{step_name}_{pin_position}"`; a different endstation could tag however makes sense to it) — the
device itself has no notion of "pin position" or "shuttle slot".
### Layer 0 — a plain image-processing toolkit (pure functions, no device, no BEC dependency)
Grayscale conversion, CLAHE, Sobel/Canny edge detection, ECC/ORB-based registration, contour
extraction, and overlay drawing (crosshair, contour outline, diff highlight) as plain
`numpy`/`opencv` functions — array in, array (or array + metadata, e.g. a fitted transform or a
contour) out. No devices, no BEC imports, trivially unit-testable in isolation, matching this
repo's existing preference for pure-function "widget math" test files (e.g.
`test_omny_tomo_params_widget_math.py`). This is the shared vocabulary both layers below build on —
neither the confirm/scoring use case nor a live processed-view use case should each hand-roll their
own edge-detection/registration code.
### Layer 1 — `VisionInterface`: a generic camera-in, processed-image-out device
The direct answer to "a camera interface that allows image manipulation... could be used as an
intermediate interface for x_ray_eye align, bypass the normal image, activate edge detection,
overlay graphics": a device that sits *between* a source camera and whatever is watching it,
publishing a transformed view instead of (or alongside) the raw feed.
- **Endstation-agnostic**, living outside `omny/` — e.g. `csaxs_bec/devices/vision/vision_interface.py`.
- **Same camera-dependency mechanism as before**: config-driven `camera_names: list[str]`, resolved
lazily via `self.device_manager.devices.get(name, None)` (the `ddg_1.py` pattern), requiring only
the shared `get_last_image()` contract — no dependency on which concrete camera class it's pointed
at.
- **A selectable processing mode**, built from Layer 0's toolkit — `"raw"`, `"grayscale"`,
`"edges"`, `"clahe"`, `"overlay"` (e.g. a stored reference's contour drawn over the live frame),
or a small ordered pipeline of these — settable at runtime via an RPC/`Signal` (e.g.
`set_mode(name: str)`), not hardcoded per device instance. This generalizes what
`push_smear_preview()`/the existing `smear_preview_toggle` do today (one hardcoded composite, one
fixed second channel) into "any of a small library of transforms, chosen at runtime".
- **Own `diagnostic_image` `PreviewSignal`**, decoupled from whichever camera it's pointed at (the
"own signal" option from the previous draft of this doc) — this is what makes it a genuine
in-between interface rather than a camera-specific patch: the GUI dock watches the
`VisionInterface`'s output, and swapping/reconfiguring the source camera or the active mode
doesn't change what the dock is looking at.
- **Two independent consumers**, justifying building this generically rather than folding it
straight into the sample-transfer use case:
- **`SampleVisionMonitor`** (Layer 2, below) uses it for registration + the diagnostic overlay it
publishes during confirm gates.
- **`x_ray_eye_align.py`**'s alignment GUI (`update_frame()`,
`flomni/x_ray_eye_align.py:114-135` — the operator watches a raw live `cam_xeye` feed and
manually places alignment points, fit later done in Matlab; OMNY's own copy is still an
unadapted LamNI leftover per `OPEN_ISSUES.md`) currently shows only the unprocessed live image.
A `VisionInterface` in front of `cam_xeye` could offer an edge-enhanced or CLAHE-normalized live
view as an operator-toggleable alternative during manual point-picking — exactly the same
exposure-invariance motivation as the sample-transfer use case, applied to a second, already-
existing manual-confirmation-style workflow. **Not proposed as a replacement for the existing
Matlab-based fit** — just a second real consumer of the same generic layer, and a concrete
illustration of why Layer 0/1 shouldn't be scoped to OMNY sample-transfer specifically.
### Layer 2 — `SampleVisionMonitor`: the sample-transfer confirm/scoring application
Everything from the previous draft of this plan, now explicitly framed as *one application built on
top of Layers 0/1*, not a separate camera-coupled implementation:
- **Runs device-server-side** (a `PSIDeviceBase` subclass, like `IDSCamera`/`VisionInterface`
itself), consistent with where camera image processing already happens in this codebase.
- **Opaque, caller-defined reference tags** — reference images and scores are grouped by a plain
string tag the caller picks (for OMNY, `f"{step_name}_{pin_position}"`); the device itself has no
notion of "pin position" or "shuttle slot".
- **Client-facing RPC surface** (sketch, names not final):
- `save_reference(tag: str) -> None` — pulls the current frame(s) from the configured camera(s)
and stores them as a labeled reference under `tag`.
- `score(tag: str) -> dict` — pulls the current frame(s), registers + scores each against every
stored reference under `tag` (see CV pipeline below), publishes a diagnostic overlay (see next
bullet), and returns the best-match score(s) plus enough detail to build a confirm message.
- `save_reference(tag: str) -> None` — pulls the current frame(s) (via its own or a shared
`VisionInterface`) and stores them as a labeled reference under `tag`.
- `score(tag: str) -> dict` — registers + scores the current frame(s) against every stored
reference under `tag` (see CV pipeline below, using Layer 0's registration/contour/SSIM
functions), publishes a diagnostic diff/overlay through the `VisionInterface` it uses, and
returns the best-match score(s) plus enough detail to build a confirm message.
- `omny_sample_transfer_mixin.py`'s gates (1-4 above) become *callers* of this device
(`dev.omny_vision_parking.score(...)`, `dev.omny_vision_samplestage.score(...)`, one device
instance per camera pair) instead of doing any `cv2`/`skimage` work themselves — the mixin only
turns the returned score into a confirm-dialog decision (per the staged rollout below).
- **Own diagnostic signal vs. borrowing the target camera's channel** — open decision, not
resolved here: (a) give `SampleVisionMonitor` its own `diagnostic_image` `PreviewSignal`
component, fully decoupled from whichever camera it's pointed at, requiring one new `Image` dock
in `gui_tools.py` per vision device; vs. (b) when the configured camera happens to expose
`push_smear_preview()` (i.e. it's an `IDSCamera`), feature-detect that and reuse the existing
dock + toggle pattern instead of adding a new one. (a) is more genuinely camera-agnostic (matches
the rest of this design); (b) is less new GUI surface for OMNY specifically, at the cost of only
working when the backing camera happens to support it. Worth prototyping both before deciding.
(`dev.omny_vision_parking.score(...)`, `dev.omny_vision_samplestage.score(...)`, one instance
per camera pair) instead of doing any `cv2`/`skimage` work themselves — the mixin only turns the
returned score into a confirm-dialog decision (per the staged rollout below).
- **Open composition question, not resolved here**: whether `SampleVisionMonitor` *contains* a
`VisionInterface` instance internally (composition), or is itself built directly on Layer 0 with
its own separate `diagnostic_image` signal and `VisionInterface` stays a purely GUI/alignment-side
concept. Composition (reusing one `VisionInterface` per camera pair, shared by both the confirm
scoring and any live processed view of that same pair) avoids two devices both owning a signal for
the same physical camera pair — likely the cleaner shape, but worth prototyping both.
## Proposed CV pipeline (classical, no deep learning)
@@ -201,13 +244,23 @@ this should not be an all-or-nothing flag flip. Proposed phases for the later im
- **Where scores/results live.** Likely alongside the existing HDF5 reference-image files (same
per-step file, additional dataset for score + registration transform), rather than a new storage
mechanism.
- **Diagnostic visualization: own `PreviewSignal` vs. borrowing the camera's `smear_preview`** —
see the architecture section above; needs a short prototype of both before committing.
- **One `SampleVisionMonitor` config per camera pair vs. one instance whose `camera_names` gets
reconfigured at call time** — static per-pair config (e.g. `omny_vision_parking`,
`omny_vision_samplestage` as two fixed device-config entries) is simpler and matches how OMNY's
own two camera pairs are already fixed, not dynamic; leaning toward this unless a concrete need
for a dynamic pairing shows up.
- **`SampleVisionMonitor` composing a `VisionInterface` vs. owning its own signal directly** — see
the "open composition question" at the end of the architecture section; needs a short prototype of
both before committing.
- **One `SampleVisionMonitor`/`VisionInterface` config per camera pair vs. one instance whose
`camera_names` gets reconfigured at call time** — static per-pair config (e.g.
`omny_vision_parking`, `omny_vision_samplestage` as two fixed device-config entries) is simpler
and matches how OMNY's own two camera pairs are already fixed, not dynamic; leaning toward this
unless a concrete need for a dynamic pairing shows up.
- **How an operator switches `VisionInterface`'s mode from the GUI.** The existing
`smear_preview_toggle` (`x_ray_eye.py:386-873`) is a single on/off switch between two fixed
channels; a `VisionInterface` with several selectable modes (raw/grayscale/edges/CLAHE/overlay)
needs a small mode picker, not just a toggle — new GUI widget surface, not sketched yet.
- **Overlay compositing vs. the GUI's own annotations.** `x_ray_eye_align.py`'s alignment GUI
already lets the operator click to place points/markers on the live image; a `VisionInterface`
"overlay" mode drawing its own graphics (contours, diff highlights) onto the frame it republishes
must not visually conflict with or obscure those widget-drawn markers — needs checking against the
actual widget code before this mode is built, not assumed compatible.
## Non-goals for this session