use nalgebra::Point2;
use serde::{Deserialize, Serialize};
pub use projective_grid::{AxisEstimate, GridCoords};
#[non_exhaustive]
#[derive(Clone, Copy, Debug, Eq, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum TargetKind {
Chessboard,
Charuco,
CheckerboardMarker,
PuzzleBoard,
}
#[non_exhaustive]
#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct LabeledCorner {
pub position: Point2<f32>,
pub grid: Option<GridCoords>,
pub id: Option<u32>,
#[serde(default)]
pub target_position: Option<Point2<f32>>,
#[serde(alias = "confidence")]
pub score: f32,
}
impl LabeledCorner {
pub fn new(position: Point2<f32>, score: f32) -> Self {
Self {
position,
grid: None,
id: None,
target_position: None,
score,
}
}
#[must_use]
pub fn with_grid(mut self, grid: GridCoords) -> Self {
self.grid = Some(grid);
self
}
#[must_use]
pub fn with_id(mut self, id: u32) -> Self {
self.id = Some(id);
self
}
#[must_use]
pub fn with_target_position(mut self, target_position: Point2<f32>) -> Self {
self.target_position = Some(target_position);
self
}
}
#[non_exhaustive]
#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct TargetDetection {
pub kind: TargetKind,
pub corners: Vec<LabeledCorner>,
}
impl TargetDetection {
pub fn new(kind: TargetKind, corners: Vec<LabeledCorner>) -> Self {
Self { kind, corners }
}
}