Skip to main content

nv_perception/
lib.rs

1//! # nv-perception
2//!
3//! Perception stage model and artifact types for the NextVision runtime.
4//!
5//! This crate defines:
6//!
7//! - **[`Stage`]** — the core user-implementable trait for per-frame processing.
8//! - **[`Detection`]**, **[`DetectionSet`]** — per-frame object detections.
9//! - **[`Track`]**, **[`TrackObservation`]**, **[`TrackState`]** — tracked objects.
10//! - **[`PerceptionArtifacts`]** — accumulated outputs of all stages for a frame.
11//! - **[`DerivedSignal`]**, **[`SignalValue`]** — generic named signals.
12//! - **[`SceneFeature`]**, **[`SceneFeatureValue`]** — scene-level feature observations.
13//! - **[`StagePipeline`]** — ordered pipeline builder with **[`validate()`](StagePipeline::validate)**.
14//! - **[`StageCapabilities`]** — declared stage inputs/outputs for validation.
15//!
16//! ## Supported model patterns
17//!
18//! The library supports multiple perception model architectures through
19//! the same [`Stage`] trait. A stage may produce *any combination* of
20//! output fields — the pipeline does not enforce a fixed detect→track
21//! sequence.
22//!
23//! | Pattern | Description |
24//! |---|---|
25//! | Classical detector → tracker | Separate detection and tracking stages in sequence. |
26//! | Joint detection+tracking | Single stage producing both `detections` and `tracks`. |
27//! | Direct track emitter | Model outputs tracks directly, no intermediate detections. |
28//! | Richer observations | Per-observation metadata via [`TrackObservation::metadata`]. |
29//! | Scene/temporal analysis | Stages producing [`SceneFeature`]s or [`DerivedSignal`]s. |
30//!
31//! See the [`Stage`] trait documentation for detailed examples and the
32//! [`StageOutput`] docs for joint-model and direct-track-emitter patterns.
33//!
34//! ## Ergonomic entity construction
35//!
36//! Use [`Detection::builder()`] and [`Track::new()`] to avoid manual struct
37//! construction. [`StageOutput::build()`] provides an incremental builder
38//! for assembling multi-field outputs, and [`StageOutput::with_artifact()`]
39//! is a shorthand for typed artifact-only output.
40//!
41//! ## Convenience re-exports
42//!
43//! This crate re-exports types that appear in [`Stage`] trait signatures
44//! so that stage authors can import everything from a single crate:
45//! [`StageId`], [`StageError`], [`FeedId`], [`ViewEpoch`], [`ViewSnapshot`],
46//! [`FrameEnvelope`], [`TypedMetadata`], and [`StageMetrics`].
47//!
48//! ## Stage execution model
49//!
50//! Stages execute linearly and synchronously within a feed. For each frame:
51//! 1. A `PerceptionArtifacts` accumulator starts empty.
52//! 2. Each stage receives a [`StageContext`] with the frame, prior artifacts,
53//!    temporal snapshot, and view snapshot.
54//! 3. Each stage returns a [`StageOutput`] that is merged into the accumulator.
55//! 4. After all stages run, the accumulator feeds the temporal store and output.
56//!
57//! Stages take `&mut self` — they run on a dedicated thread per feed and are
58//! never shared across threads.
59//!
60//! ## Single `Stage` trait
61//!
62//! The library uses one trait for all stage types — detection, tracking,
63//! classification, scene analysis, etc. Specialization happens by convention
64//! (which [`StageOutput`] fields a stage populates), not by type hierarchy.
65//! The abstraction stays minimal, avoids taxonomy assumptions, and lets
66//! users compose arbitrary pipeline shapes.
67//!
68//! ## Extension seam: typed artifacts
69//!
70//! For inter-stage data that does not fit the built-in fields (feature maps,
71//! prepared clip/window tensors, calibration data), stages use the
72//! [`stage_artifacts`](PerceptionArtifacts::stage_artifacts) type-map.
73//! A pre-processing stage can assemble a sliding window and store it as a
74//! typed artifact for a downstream inference stage to consume.
75//!
76//! ## Backend independence
77//!
78//! This crate has no dependency on GStreamer or any media backend. Stages
79//! receive `FrameEnvelope` (generic pixel data)
80//! and produce domain-agnostic artifacts.
81
82pub mod artifact;
83pub mod batch;
84pub mod detection;
85pub mod pipeline;
86pub mod scene;
87pub mod signal;
88pub mod stage;
89pub mod temporal_access;
90pub mod track;
91
92pub use artifact::PerceptionArtifacts;
93pub use batch::{BatchEntry, BatchProcessor};
94pub use detection::{Detection, DetectionBuilder, DetectionSet};
95pub use pipeline::{
96    StagePipeline, StagePipelineBuilder, ValidationMode, ValidationWarning,
97    validate_pipeline_phased, validate_stages,
98};
99pub use scene::{SceneFeature, SceneFeatureValue};
100pub use signal::{DerivedSignal, SignalValue};
101pub use stage::{
102    Stage, StageCapabilities, StageCategory, StageContext, StageOutput, StageOutputBuilder,
103};
104pub use temporal_access::TemporalAccess;
105pub use track::{Track, TrackObservation, TrackState};
106
107// Re-export types that appear in Stage trait signatures and StageContext,
108// so that stage authors can import everything from `nv_perception` without
109// needing direct dependencies on nv-core, nv-frame, or nv-view.
110pub use nv_core::TypedMetadata;
111pub use nv_core::error::StageError;
112pub use nv_core::id::{FeedId, StageId};
113pub use nv_core::metrics::StageMetrics;
114pub use nv_frame::FrameEnvelope;
115pub use nv_view::{ViewEpoch, ViewSnapshot};