qualia_vision/biosense/biometrics/
template_hash.rs1use crate::biosense::consent::BiosenseConsent;
5use crate::biosense::face::FaceRoi;
6use crate::cv::buffer::RgbView;
7use crate::cv::error::CvError;
8
9#[derive(Debug, Clone, Copy)]
10pub struct BiometricTemplate {
11 pub hash: u64,
12 pub principal_hash: u64,
13 pub method: &'static str,
14}
15
16pub fn template_hash_from_roi(
18 consent: BiosenseConsent,
19 src: RgbView<'_>,
20 roi: FaceRoi,
21) -> Result<BiometricTemplate, CvError> {
22 if !consent.may_process() || !consent.allow_store_template {
23 return Err(CvError::InvalidParameter);
24 }
25 let mut h = 0xcbf2_9ce4_8422_2325u64;
26 let x2 = (roi.x + roi.w).min(src.width);
27 let y2 = (roi.y + roi.h).min(src.height);
28 for y in roi.y..y2 {
29 for x in roi.x..x2 {
30 let (r, g, b) = src.pixel(x, y);
31 h ^= r as u64;
32 h = h.wrapping_mul(0x100_0000_01b3);
33 h ^= g as u64;
34 h = h.wrapping_mul(0x100_0000_01b3);
35 h ^= b as u64;
36 h = h.wrapping_mul(0x100_0000_01b3);
37 }
38 }
39 Ok(BiometricTemplate {
40 hash: h,
41 principal_hash: consent.principal_hash,
42 method: "roi_fnv_proxy_v1_not_production_embedding",
43 })
44}
45
46pub fn templates_match(a: BiometricTemplate, b: BiometricTemplate) -> bool {
48 a.hash == b.hash && a.principal_hash == b.principal_hash
49}