euclideanDistance static method
Computes the Euclidean (L2) distance between two embedding vectors.
Euclidean distance measures the straight-line distance between two points. For face embeddings:
- Values < 0.6 strongly suggest the same person
- Values < 0.8 suggest the same person
- Values > 1.0 suggest different people
Note: Threshold values assume normalized embeddings.
Example:
final distance = FaceEmbedding.euclideanDistance(embedding1, embedding2);
if (distance < 0.6) {
print('Very likely the same person');
}
Implementation
static double euclideanDistance(Float32List a, Float32List b) {
if (a.length != b.length) {
throw ArgumentError(
'Embedding dimensions must match: ${a.length} vs ${b.length}',
);
}
double sum = 0.0;
for (int i = 0; i < a.length; i++) {
final double diff = a[i] - b[i];
sum += diff * diff;
}
return math.sqrt(sum);
}