Skip to main content

fprint_pipeline/
detector.rs

1// SPDX-FileCopyrightText: 2026 fprintd (pure-Rust) contributors
2//
3// SPDX-License-Identifier: MIT OR Apache-2.0
4
5//! The minutiae detector seam — the front half of the pipeline, onto [`fprint_mindtct`].
6//!
7//! It turns a captured 8-bit grayscale frame into an [`fprint_core::Template::Nbis`] by calling
8//! [`fprint_mindtct::detect_minutiae`] and converting each public-domain
9//! [`fprint_mindtct::Minutia`] into an [`fprint_core::Minutia`], so a caller can go
10//! **image → minutiae → match** end-to-end (the back half is [`crate::matcher`]).
11//!
12//! The conversion lives here rather than in `fprint-mindtct`: that crate is a self-contained,
13//! dependency-free public-domain kernel that does not know `fprint-core`, and the only thing
14//! crossing the boundary is the `xyt` triple — an interoperability *fact*, not a code coupling.
15//! Keeping the `Minutia → fprint_core::Minutia` mapping in this pipeline crate lets the PD detector
16//! and PD matcher each define their own `Minutia`.
17
18use fprint_core::{Minutia, Template};
19
20/// Detect the minutiae in a captured 8-bit grayscale frame, as [`fprint_core::Minutia`]s.
21///
22/// Runs the full MINDTCT pipeline ([`fprint_mindtct::detect_minutiae`]) over `img` and projects each
23/// detected point onto the domain minutia. The `xyt` triple (`x`, `y`, `theta`) is carried through
24/// verbatim — the same interoperability fact the matcher consumes — and MINDTCT's per-point
25/// `quality` is dropped, because `fprint_core::Minutia` (like libfprint's `xyt_struct` for BOZORTH3)
26/// does not carry it. An image with no detectable ridge structure yields an empty vector.
27#[must_use]
28pub fn extract_minutiae(img: fprint_mindtct::GrayImage<'_>) -> Vec<Minutia> {
29    fprint_mindtct::detect_minutiae(img)
30        .iter()
31        .map(minutia_to_core)
32        .collect()
33}
34
35/// Build a host-side [`fprint_core::Template::Nbis`] from a set of captured frames.
36///
37/// Each frame is detected independently ([`extract_minutiae`]) and becomes one inner minutiae vector
38/// — the `Vec<Vec<Minutia>>` shape an image-capture sensor enrolls, one sample per capture. This is
39/// always an `Nbis` template (even for a single frame, and even if a frame detects zero minutiae:
40/// that empty sample is preserved so the sample count mirrors the captures); the matcher takes the
41/// maximum score over the samples, so more captures only ever help.
42#[must_use]
43pub fn template_from_images(images: &[fprint_mindtct::GrayImage<'_>]) -> Template {
44    Template::Nbis(images.iter().map(|&img| extract_minutiae(img)).collect())
45}
46
47/// Convert one MINDTCT [`fprint_mindtct::Minutia`] into an [`fprint_core::Minutia`].
48///
49/// The `xyt` triple (`x`, `y`, `theta`) is carried through verbatim — the interoperability fact both
50/// the detector and the matcher share — and MINDTCT's per-point `quality` is dropped, because
51/// `fprint_core::Minutia` (like libfprint's `xyt_struct` for BOZORTH3) does not carry it. This is the
52/// public form of the `mindtct → core` seam that [`extract_minutiae`] applies per detected point.
53#[inline]
54#[must_use]
55pub fn minutia_to_core(m: &fprint_mindtct::Minutia) -> Minutia {
56    Minutia {
57        x: m.x,
58        y: m.y,
59        theta: m.theta,
60    }
61}