verify method
Verify a detected face against enrolled templates.
Implementation
@override
Future<FaceVerificationResult> verify(Face face) async {
final features = FaceFeatureExtractor.extractFeatures(face);
if (features == null) {
return const FaceVerificationResult(
isMatch: false,
confidence: 0.0,
);
}
final templates = await store.getAll();
if (templates.isEmpty) {
// No enrolled templates — can't verify, treat as match
// (detection-only mode when no templates exist).
return const FaceVerificationResult(
isMatch: true,
confidence: 1.0,
);
}
String? bestId;
var bestScore = 0.0;
for (final template in templates) {
final score = FaceFeatureExtractor.cosineSimilarity(
features,
template.features,
);
if (score > bestScore) {
bestScore = score;
bestId = template.id;
}
}
return FaceVerificationResult(
isMatch: bestScore >= minMatchScore,
confidence: bestScore.clamp(0.0, 1.0),
matchedTemplateId: bestScore >= minMatchScore ? bestId : null,
);
}