AI Overlay API

AI Overlay Control Client

Control the platform’s AI overlay system that draws detection boxes, labels, and confidence scores directly on NV12 frames before encoding. Zero CPU cost — drawing happens in camera-daemon before encoding.

Two halves:

  • configuration — enable / disable / configure / apply via the UpdateAiOverlay RPC;

  • content — annotate / annotate_result push detection boxes (or classifications / landmarks / OCR lines) through the event bus; camera-daemon’s overlay subscriber renders them with its HAL draw ops.

Uses gRPC over Unix domain socket, consistent with other SDK clients.

class neoruntime_ipc_sdk.overlay.OverlayConfig(enabled=True, show_label=True, show_confidence=True, line_thickness=2, box_color=0, label_color=0, font_size=0, strict_frame_lock=None, strict_wait_cap_ms=None)[source]

Bases: object

AI overlay configuration.

strict_frame_lock / strict_wait_cap_ms mirror the optional wire fields: None (the default) leaves them unset, so the daemon keeps its current (yaml) strict settings.

enabled: bool = True
show_label: bool = True
show_confidence: bool = True
line_thickness: int = 2
box_color: int = 0
label_color: int = 0
font_size: int = 0
strict_frame_lock: bool | None = None
strict_wait_cap_ms: int | None = None
to_proto()[source]
__init__(enabled=True, show_label=True, show_confidence=True, line_thickness=2, box_color=0, label_color=0, font_size=0, strict_frame_lock=None, strict_wait_cap_ms=None)
class neoruntime_ipc_sdk.overlay.OverlayClient(*args, **kwargs)[source]

Bases: GrpcClient

AI Overlay Control Client

Uses gRPC to communicate with camera-daemon’s CameraControl service.

Usage:

from neoruntime_ipc_sdk import OverlayClient

oc = OverlayClient()

# Enable overlay with default settings
oc.enable()

# Customize appearance
oc.configure(
    show_label=True,
    show_confidence=True,
    line_thickness=3,
)

# Disable overlay
oc.disable()
Environment variables:
CAMERA_CONTROL_ENDPOINT: Camera control gRPC endpoint

(default: unix:///run/aipc/camera-control.sock)

__init__(*args, **kwargs)[source]
close()[source]
property channel_options

gRPC channel options applied at connect time.

enable(show_label=True, show_confidence=True, line_thickness=2)[source]

Enable AI overlay with specified settings.

disable()[source]

Disable AI overlay.

configure(enabled=True, show_label=True, show_confidence=True, line_thickness=2, box_color=0, label_color=0, font_size=0, strict_frame_lock=None, strict_wait_cap_ms=None)[source]

Configure AI overlay with full control.

Parameters:
  • enabled (bool) – Enable or disable overlay

  • show_label (bool) – Show class label on detections

  • show_confidence (bool) – Show confidence score on detections

  • line_thickness (int) – Box line thickness (1-10)

  • box_color (int) – Box color in ARGB format (e.g. 0xFFFF0000 for red)

  • label_color (int) – Label color in ARGB format

  • font_size (int) – Font size (8-72)

  • strict_frame_lock (bool | None) – opt in to / opt out of strict frame-lock on identity-fed display streams (streams whose stream_map entry feeds them their own inference results). Strict mode waits — bounded by strict_wait_cap_ms — for each frame’s own inference result at the bake site, so a box lands on the frame it was computed from instead of the newest frame. None keeps the daemon’s current setting.

  • strict_wait_cap_ms (int | None) – max ms the bake site waits per frame before degrading to the freshest result (warned + counted). 0 derives the cap from the stream fps (2 frame periods, clamp [1, 500]). None keeps the current setting; only meaningful together with strict_frame_lock.

apply(config)[source]

Apply an OverlayConfig object.

annotate(stream_id, detections=None, *, polygons=None, ttl_ms=None, session_id=None, frame_sequence=None, stream_epoch=None)[source]

Draw detection boxes / zone polygons on stream_id’s video.

Parameters:
  • stream_id (str) – the camera stream the boxes belong to (e.g. "main") — camera-daemon keys overlay results by it.

  • detections (list | None) – DetectedObject items or dicts with label / score (or confidence) and bbox ({"x","y","width","height"} or [x, y, w, h]). A detection’s track_id (>= 0) rides along and renders as a #id label suffix. None leaves the stream’s previous boxes untouched, so polygons can push alone.

  • polygons (list | None) – dicts {"points": [[x, y], ...], "label": str, "closed": bool, "color": ARGB int, "thickness": px int (-1 = filled)} with only points required — points are normalized [0, 1] floats, 2..128 per polygon, at most 16 polygons per call. Any list ([] included) replaces the stream’s previous polygons; None keeps them.

  • ttl_ms (int | None) – positive int — per-event validity override for the stream’s results. Omitted: the daemon derives a default from the stream’s fps (about two frame periods).

  • session_id (str | None) – tag this event as belonging to a lifecycle session (P2-13). The daemon marks the stream’s results with the tag and a "session/end" event sweeps matching tagged polygons on disconnect; an untagged write resets the mark. None / "" leave the event untagged.

  • frame_sequence (int | None) – bind this event to that frame of the stream (positive int — InferenceResult.frame_sequence from a subscribe() iteration is the natural source). The daemon draws the layer only while the bake site is within its frame-bind slack of it, then expires it, and rejects events whose frame the pipeline already passed. None leaves the event unbound (legacy semantics).

  • stream_epoch (int | None) – the stream generation counter (positive int, from get_stream_status()’s stream_epoch) this event was made against. A ReconfigureEncoder restart bumps the epoch — the daemon rejects events carrying a stale one instead of drawing ghosts over the new generation. None skips the check.

Returns:

The published event id.

Return type:

str

Results expire ttl_ms after the last event (fps-derived default), so call this at a few Hz while detections are fresh — publish an empty detections list to clear boxes, an empty polygons list to clear zones. The overlay itself must be on: enable() first.

oc = OverlayClient()
oc.enable()
for result in inf.subscribe(stream, model):
    oc.annotate(stream, result.objects)

# zone polygons ride independently of the boxes channel
oc.annotate(stream, polygons=[{"points": ZONE, "label": "yard"}])
annotate_result(stream_id, result, *, ttl_ms=None, session_id=None, frame_sequence=None, stream_epoch=None)[source]

Push whichever section of an InferenceResult is populated.

Detections take precedence, then classifications, landmarks and OCR lines — a payload carries one kind (that is how camera-daemon’s parser discriminates them). An empty result publishes zero detections, clearing stale boxes. ttl_ms overrides the stream’s result validity window for this event. session_id tags the event with a lifecycle session (P2-13). frame_sequence / stream_epoch bind the event to the stream’s frame generation — see annotate().

OverlayClient

class neoruntime_ipc_sdk.OverlayClient(*args, **kwargs)[source]

Bases: GrpcClient

AI Overlay Control Client

Uses gRPC to communicate with camera-daemon’s CameraControl service.

Usage:

from neoruntime_ipc_sdk import OverlayClient

oc = OverlayClient()

# Enable overlay with default settings
oc.enable()

# Customize appearance
oc.configure(
    show_label=True,
    show_confidence=True,
    line_thickness=3,
)

# Disable overlay
oc.disable()
Environment variables:
CAMERA_CONTROL_ENDPOINT: Camera control gRPC endpoint

(default: unix:///run/aipc/camera-control.sock)

__init__(*args, **kwargs)[source]
close()[source]
property channel_options

gRPC channel options applied at connect time.

enable(show_label=True, show_confidence=True, line_thickness=2)[source]

Enable AI overlay with specified settings.

disable()[source]

Disable AI overlay.

configure(enabled=True, show_label=True, show_confidence=True, line_thickness=2, box_color=0, label_color=0, font_size=0, strict_frame_lock=None, strict_wait_cap_ms=None)[source]

Configure AI overlay with full control.

Parameters:
  • enabled (bool) – Enable or disable overlay

  • show_label (bool) – Show class label on detections

  • show_confidence (bool) – Show confidence score on detections

  • line_thickness (int) – Box line thickness (1-10)

  • box_color (int) – Box color in ARGB format (e.g. 0xFFFF0000 for red)

  • label_color (int) – Label color in ARGB format

  • font_size (int) – Font size (8-72)

  • strict_frame_lock (bool | None) – opt in to / opt out of strict frame-lock on identity-fed display streams (streams whose stream_map entry feeds them their own inference results). Strict mode waits — bounded by strict_wait_cap_ms — for each frame’s own inference result at the bake site, so a box lands on the frame it was computed from instead of the newest frame. None keeps the daemon’s current setting.

  • strict_wait_cap_ms (int | None) – max ms the bake site waits per frame before degrading to the freshest result (warned + counted). 0 derives the cap from the stream fps (2 frame periods, clamp [1, 500]). None keeps the current setting; only meaningful together with strict_frame_lock.

apply(config)[source]

Apply an OverlayConfig object.

annotate(stream_id, detections=None, *, polygons=None, ttl_ms=None, session_id=None, frame_sequence=None, stream_epoch=None)[source]

Draw detection boxes / zone polygons on stream_id’s video.

Parameters:
  • stream_id (str) – the camera stream the boxes belong to (e.g. "main") — camera-daemon keys overlay results by it.

  • detections (list | None) – DetectedObject items or dicts with label / score (or confidence) and bbox ({"x","y","width","height"} or [x, y, w, h]). A detection’s track_id (>= 0) rides along and renders as a #id label suffix. None leaves the stream’s previous boxes untouched, so polygons can push alone.

  • polygons (list | None) – dicts {"points": [[x, y], ...], "label": str, "closed": bool, "color": ARGB int, "thickness": px int (-1 = filled)} with only points required — points are normalized [0, 1] floats, 2..128 per polygon, at most 16 polygons per call. Any list ([] included) replaces the stream’s previous polygons; None keeps them.

  • ttl_ms (int | None) – positive int — per-event validity override for the stream’s results. Omitted: the daemon derives a default from the stream’s fps (about two frame periods).

  • session_id (str | None) – tag this event as belonging to a lifecycle session (P2-13). The daemon marks the stream’s results with the tag and a "session/end" event sweeps matching tagged polygons on disconnect; an untagged write resets the mark. None / "" leave the event untagged.

  • frame_sequence (int | None) – bind this event to that frame of the stream (positive int — InferenceResult.frame_sequence from a subscribe() iteration is the natural source). The daemon draws the layer only while the bake site is within its frame-bind slack of it, then expires it, and rejects events whose frame the pipeline already passed. None leaves the event unbound (legacy semantics).

  • stream_epoch (int | None) – the stream generation counter (positive int, from get_stream_status()’s stream_epoch) this event was made against. A ReconfigureEncoder restart bumps the epoch — the daemon rejects events carrying a stale one instead of drawing ghosts over the new generation. None skips the check.

Returns:

The published event id.

Return type:

str

Results expire ttl_ms after the last event (fps-derived default), so call this at a few Hz while detections are fresh — publish an empty detections list to clear boxes, an empty polygons list to clear zones. The overlay itself must be on: enable() first.

oc = OverlayClient()
oc.enable()
for result in inf.subscribe(stream, model):
    oc.annotate(stream, result.objects)

# zone polygons ride independently of the boxes channel
oc.annotate(stream, polygons=[{"points": ZONE, "label": "yard"}])
annotate_result(stream_id, result, *, ttl_ms=None, session_id=None, frame_sequence=None, stream_epoch=None)[source]

Push whichever section of an InferenceResult is populated.

Detections take precedence, then classifications, landmarks and OCR lines — a payload carries one kind (that is how camera-daemon’s parser discriminates them). An empty result publishes zero detections, clearing stale boxes. ttl_ms overrides the stream’s result validity window for this event. session_id tags the event with a lifecycle session (P2-13). frame_sequence / stream_epoch bind the event to the stream’s frame generation — see annotate().

OverlayConfig

class neoruntime_ipc_sdk.OverlayConfig(enabled=True, show_label=True, show_confidence=True, line_thickness=2, box_color=0, label_color=0, font_size=0, strict_frame_lock=None, strict_wait_cap_ms=None)[source]

AI overlay configuration.

strict_frame_lock / strict_wait_cap_ms mirror the optional wire fields: None (the default) leaves them unset, so the daemon keeps its current (yaml) strict settings.

enabled: bool = True
show_label: bool = True
show_confidence: bool = True
line_thickness: int = 2
box_color: int = 0
label_color: int = 0
font_size: int = 0
strict_frame_lock: bool | None = None
strict_wait_cap_ms: int | None = None
to_proto()[source]
__init__(enabled=True, show_label=True, show_confidence=True, line_thickness=2, box_color=0, label_color=0, font_size=0, strict_frame_lock=None, strict_wait_cap_ms=None)

Usage Examples

Enable the overlay

from neoruntime_ipc_sdk import OverlayClient

overlay = OverlayClient()

# Enable the hardware overlay: draw detection boxes + labels +
# confidence on the video.
overlay.enable(show_label=True, show_confidence=True, line_thickness=2)

# Disable
overlay.disable()

Custom styling

# configure sets every style parameter in one call
overlay.configure(
    enabled=True,
    show_label=True,
    show_confidence=False,
    line_thickness=3,
    box_color=0x00FF00,     # green boxes
    label_color=0xFFFFFF,   # white labels
    font_size=16,
)

Structured configuration

from neoruntime_ipc_sdk import OverlayClient, OverlayConfig

config = OverlayConfig(
    enabled=True,
    show_label=True,
    show_confidence=True,
    line_thickness=2,
)
OverlayClient().apply(config)

Strict frame-lock mode (P1-6)

# The default is "live preview" semantics: the bake site draws the
# freshest unexpired result, so boxes and pixels are not guaranteed
# to be from the same frame. Strict frame-lock is opt-in: once
# enabled, camera-daemon waits — bounded — at the bake site (before
# encoding) for each frame's OWN inference result; on timeout it
# degrades to the freshest result (logged + counted), so encoded
# output never stalls on the wait.
overlay.configure(strict_frame_lock=True)              # enable (cap derived from fps)
overlay.configure(strict_frame_lock=True,
                  strict_wait_cap_ms=0)                # 0 = derive from stream fps (2 frame periods)
overlay.configure(strict_frame_lock=True,
                  strict_wait_cap_ms=66)               # explicit 66 ms cap
overlay.configure(strict_frame_lock=False)             # explicitly leave strict mode

# Both arguments are optional-field semantics: omitted = keep the
# daemon's current setting; enable()/disable() and a bare configure()
# never touch strict mode.

# Strict mode only gates identity-fed display streams — stream_map
# entries whose display stream is fed its own inference results
# (e.g. main:main). Cross-fed streams (e.g. third:main) keep live
# preview semantics.

# Strict mode locks only the platform result layer — app layers
# (annotate() drawings) are never excluded: with a locked platform
# layer they draw on top of it under their own TTL semantics; on a
# SKIP / degraded bake (no platform result to lock this frame) they
# draw alone instead of being wiped. Strict never suppresses the
# locked platform layer (the frame-sync guarantee is the point of
# the mode) and never admits cross-fed platform layers; the frame
# ships clean (bake_skips) only when there is neither a locked layer
# nor a live app layer.

Combining with inference results (annotate)

# annotate() pushes detections through the event bus to
# camera-daemon's overlay renderer: the app never touches video
# frames — the daemon draws the boxes onto the stream before
# encoding. Results expire after 500 ms, so call at inference
# cadence; publish an empty list to clear the screen.
from neoruntime_ipc_sdk import OverlayClient

overlay = OverlayClient()
overlay.enable()

for result in inference_results:      # e.g. InferenceClient.subscribe(...)
    overlay.annotate("main", result.objects)

overlay.annotate("main", [])          # clear

Other result kinds

# annotate_result picks whichever section of an InferenceResult is
# populated, with precedence objects > classifications > landmarks
# > ocr_lines
overlay.annotate_result("main", result)

Lifecycle session tag (P2-13)

# annotate / annotate_result / polygon writes all accept session_id:
# drawings belonging to one session carry the same tag. When the
# inference session ends (including the connection drop after the
# app is SIGKILLed), camera-daemon sweeps every polygon carrying
# that tag in one shot on the session/end event; detection boxes
# themselves expire via the result TTL.
overlay.annotate("main", result.objects, session_id="app-1")
overlay.annotate("main", polygons=zones, session_id="app-1")

# Omitting session_id = operator write: takes effect unconditionally
# and never participates in session cleanup. StreamPipeline draws
# exactly this distinction — result drawings are tagged, while the
# static zones at start and the clear writes at stop() are not.

Two modes and the video side-effect contract

The SDK offers two non-interfering ways to consume video data, with an explicit contract for each:

Results only (zero video side effects): InferenceClient.subscribe(...) returns inference results and touches no video path. The platform’s own models (results published by ai-runtime / auto-infer) also do not alter the stream by default — unless the operator binds them explicitly in the daemon config (next section). annotate() is not a side-effect violation: it is a drawing command the app issues on purpose.

Fetch frames, draw yourself (keep_fd / copy): FdMediaClient’s keep_fd / copy modes hand out clean frames (never baked by the overlay). The app composites on its own buffers: copy frames are yours to write directly; keep_fd frames go through DSP_IMPORT into the app’s own DSP pool for RESIZE→BLEND (per-call cost is acceptable with the P1-9 resident pools). A keep_fd frame is never a DSP write target or blend base — the platform enforces the read-only contract (writes are rejected); dsp-import-write-target-test guards it.

Platform result bindings (daemon config)

Platform model detections are not drawn by default (behavior decoupling): a bare subscribe() must not change any video output. To enable platform boxes, bind the streams explicitly in the daemon config yaml under [ai_overlay]:

[ai_overlay]
# infer stream:display stream, same direction as stream_map;
# comma-separated for multiple bindings
bindings: "main:main,third:main"
# Migration switch: restores the old behavior (every platform result
# auto-drawn + the default stream_map backfill)
legacy_auto_bind: 0

Migration note: legacy_auto_bind defaults to off. If platform boxes disappear after an upgrade, either (1) add the streams you need to bindings as above (recommended: enable only what you use), or (2) set legacy_auto_bind: 1 for the full legacy behavior (every platform result auto-bound, including the default stream_map backfill). Drawings the app issues via annotate() are unaffected by the switch — they always take effect.

Frame-sync binding (frame_sequence / stream_epoch)

# annotate / annotate_result accept two optional frame-sync params
# (both ride event metadata, never the payload; omitted = unbound,
# keeping the legacy semantics)
#
# frame_sequence: bind this drawing to that frame — it draws only
#   while the bake site is within the frame-bind slack (+2 frames)
#   of it, then expires; commands whose frame the pipeline already
#   passed are rejected (overlay_late_commands counter).
#   result.frame_sequence from a subscribe() iteration is the
#   natural source.
#   Note: frame_sequence is the HAL's SHARED frame counter — all
#   streams of one media context (main/sub/...) draw from the same
#   counter, so sequences ARE comparable across streams. Sourcing
#   from another stream's results still adds cross-stream latency
#   (inference time lands in counter steps) that can eat into the
#   bind window: prefer the target display stream's own subscribe()
#   results; cross-stream sources work but show on fewer frames. The
#   bind window auto-scales to display-stream frames (each frame
#   spans several shared-counter steps on multi-stream devices).
# stream_epoch: the stream generation counter (readable via
#   get_stream_status()). Reconfiguration (ReconfigureEncoder /
#   resolution and full transform reinit) bumps the epoch and purges
#   held layers; events carrying a stale epoch are rejected
#   (overlay_epoch_rejects counter) instead of turning into ghost
#   boxes.
for result in stream.subscribe(model):
    overlay.annotate_result("main", result,
                            frame_sequence=result.frame_sequence,
                            stream_epoch=epoch)

# Self-healing after a reconfigure: notice the epoch changed, then
# keep publishing with the new one. On a reconfigure / pipeline
# rebuild the platform bumps the epoch AND drops the stream's
# sequence anchor — the HAL counter may restart from small values
# in the new generation, so do not reuse a frame_sequence captured
# before the rebuild; re-subscribe and bind against fresh numbers.
status = {s.stream_id: s for s in camera.get_stream_status()}
epoch = status["main"].stream_epoch

The keep_fd read-only recipe

# copy mode: the frame is the app's own memory — write freely
frame = media.get_frame(stream, copy=True)
draw_boxes(frame, results)

# keep_fd mode: the dma-buf is read-only. Import it via DSP_IMPORT
# into the app's own DSP pool, RESIZE to the target size and use it
# as the BLEND overlay layer over the app's own base; the frame
# itself is never a write target — a RESIZE dst / BLEND base
# pointing at a keep_fd frame is rejected by the platform
# (enforced, not a convention).
dsp.import_buffer(frame.fds, frame_id=frame.frame_id)
dsp.schedule(op=DSP_OP_RESIZE, src=imported, dst=scratch)      # own scratch
dsp.schedule(op=DSP_OP_BLEND, base=composed, overlay=scratch)  # own base
# In short: a keep_fd frame = a BLEND overlay input or RESIZE src;
#           the app's own buffers = every write target.

Context manager

with OverlayClient() as overlay:
    overlay.enable()