UNPKG

@vladmandic/face-api

Version:

FaceAPI: AI-powered Face Detection & Rotation Tracking, Face Description & Recognition, Age & Gender & Emotion Prediction for Browser and NodeJS using TensorFlow/JS

13 lines (10 loc) 398 B
export function euclideanDistance(arr1: number[] | Float32Array, arr2: number[] | Float32Array) { if (arr1.length !== arr2.length) throw new Error('euclideanDistance: arr1.length !== arr2.length'); const desc1 = Array.from(arr1); const desc2 = Array.from(arr2); return Math.sqrt( desc1 .map((val, i) => val - desc2[i]) .reduce((res, diff) => res + (diff ** 2), 0), ); }