Files
VisionPOC/Sources/Process
james.maesandClaude Opus 4.7 878fc9aece Add face recognition with enrollment via the menu bar
Vision's public API doesn't expose a face-specific embedding model, so
we use VNGenerateImageFeaturePrintRequest with each face's bounding box
as the regionOfInterest. The general-purpose image FeaturePrint applied
to a padded face crop produces distance metrics that separate "same
person" from "different person" reliably for the small number of
enrolled identities a POC needs.

Components
- Sources/Process/FaceRegistry.swift — thread-safe enrollment store.
  Persists per-person VNFeaturePrintObservation arrays to
  ~/Library/Application Support/VisionPOC/faces.json via NSKeyedArchiver.
  bestMatch(for:) walks every stored template and returns the closest
  name + distance under matchThreshold.
- ObjectDetector now generates a feature print per detected face on
  each YOLO refresh, matches against the registry, and labels the
  detection with the matched name (uppercased) instead of "FACE" when
  it recognizes someone.

Enrollment flow
- New Faces menu in the menu bar.
- ⌘E "Enroll Face…" prompts for a name, then captures feature prints
  from the next 5 frames that contain the largest face in view, saves
  them, and shows a confirmation alert.
- ⌘⇧E "Forget Face…" lists enrolled names in a popup and deletes the
  selected entry from disk.
- ObjectDetector.captureFeaturePrints(count:completion:) drives the
  capture: the next N detect-pass frames that see a face have the
  largest face's print collected, then the completion fires once N
  prints are in hand.

Threading
- The detector completion runs on the detector queue and feeds the
  prints straight into FaceRegistry.enroll (which is thread-safe).
  Only the count is sent back to MainActor for the confirmation
  dialog, sidestepping the Sendable issues with passing
  VNFeaturePrintObservation across actor boundaries.

Threshold note
- FaceRegistry.matchThreshold defaults to 18.0 — tuned for the image-
  level FeaturePrint distances we see on face crops. Apple's published
  ~0.6 threshold targets face-specific embedding models that aren't
  exposed publicly. The threshold is a `var` so it's tunable at runtime
  if real-world testing wants it tighter or looser.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-16 14:58:44 -05:00
..