vision_core/
interfaces.rs

1use serde::{Deserialize, Serialize};
2use std::path::PathBuf;
3
4// Re-export label types from data_contracts (canonical source)
5pub use data_contracts::{DetectionLabel as Label, LabelSource};
6
7/// A frame of image data and associated metadata.
8#[derive(Debug, Clone, Serialize, Deserialize)]
9pub struct Frame {
10    pub id: u64,
11    /// Sim or capture timestamp (seconds).
12    pub timestamp: f64,
13    /// Optional raw RGBA8 data; can be `None` when operating on file-based frames.
14    pub rgba: Option<Vec<u8>>,
15    /// Image dimensions (width, height).
16    pub size: (u32, u32),
17    /// Optional on-disk location for lazy loading.
18    pub path: Option<PathBuf>,
19}
20
21/// Result of running a detector on a frame.
22#[derive(Debug, Clone, Serialize, Deserialize)]
23pub struct DetectionResult {
24    pub frame_id: u64,
25    pub positive: bool,
26    pub confidence: f32,
27    /// Normalized boxes \[x0,y0,x1,y1\] in 0..1.
28    pub boxes: Vec<[f32; 4]>,
29    /// Per-box scores aligned with `boxes`.
30    pub scores: Vec<f32>,
31}
32
33/// Data passed to a recorder sink.
34#[derive(Debug)]
35pub struct FrameRecord<'a> {
36    pub frame: Frame,
37    pub labels: &'a [Label],
38    pub camera_active: bool,
39    pub label_seed: u64,
40}
41
42/// Pulls frames from some source (capture camera, file, test generator).
43pub trait FrameSource {
44    fn next_frame(&mut self) -> Option<Frame>;
45}
46
47/// Runs inference on a frame.
48pub trait Detector {
49    fn detect(&mut self, frame: &Frame) -> DetectionResult;
50    /// Optional: adjust thresholds at runtime.
51    fn set_thresholds(&mut self, _obj: f32, _iou: f32) {}
52}
53
54/// Persists frames/metadata to a sink (disk, stream, etc).
55pub trait Recorder {
56    fn record(&mut self, record: &FrameRecord) -> std::io::Result<()>;
57}
58
59/// Optional factory for feature-flagged Burn model runtime.
60pub trait BurnDetectorFactory {
61    type Detector: Detector;
62    fn load(model_path: &std::path::Path) -> anyhow::Result<Self::Detector>;
63}