use sightloom_core::{Detection, FrameStamp};
use sightloom_reid::SubjectModality;
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub enum PixelFormat {
Gray8,
Rgb8,
Bgr8,
Rgba8,
Custom(u32),
}
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub struct FrameView<'a> {
pub width: u32,
pub height: u32,
pub stride: usize,
pub format: PixelFormat,
pub data: &'a [u8],
}
impl<'a> FrameView<'a> {
#[must_use]
pub const fn new(
width: u32,
height: u32,
stride: usize,
format: PixelFormat,
data: &'a [u8],
) -> Self {
Self {
width,
height,
stride,
format,
data,
}
}
}
pub trait DetectorAdapter {
type Error: core::fmt::Debug;
fn detect(
&mut self,
stamp: FrameStamp,
frame: &FrameView<'_>,
) -> Result<Vec<Detection>, Self::Error>;
}
pub trait TrackEmbeddingAdapter {
type Error: core::fmt::Debug;
fn embed_track(
&mut self,
stamp: FrameStamp,
frame: &FrameView<'_>,
track_key: sightloom_core::TrackKey,
bbox: sightloom_core::Rect,
) -> Result<Vec<f32>, Self::Error>;
}
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub enum EmbeddingTask {
Face,
PersonReId,
GenericAppearance,
}
impl EmbeddingTask {
#[must_use]
pub const fn to_modality(self) -> SubjectModality {
match self {
Self::Face => SubjectModality::Face,
Self::PersonReId => SubjectModality::PersonAppearance,
Self::GenericAppearance => SubjectModality::GenericObject,
}
}
}
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub struct PhotoView<'a> {
pub frame: Option<FrameView<'a>>,
pub encoded: Option<&'a [u8]>,
}
impl<'a> PhotoView<'a> {
#[must_use]
pub const fn from_frame(frame: FrameView<'a>) -> Self {
Self {
frame: Some(frame),
encoded: None,
}
}
#[must_use]
pub const fn from_encoded(encoded: &'a [u8]) -> Self {
Self {
frame: None,
encoded: Some(encoded),
}
}
}
pub trait PhotoEmbeddingAdapter {
type Error: core::fmt::Debug;
fn task(&self) -> EmbeddingTask;
fn embed_photo(&mut self, photo: &PhotoView<'_>) -> Result<Vec<f32>, Self::Error>;
}