vision_core/
interfaces.rs

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