694 B
694 B
If you already have the reference face (like the user profile picture), extract the descriptor of both the selfie and the reference image, and compare them.
async function compareFaces(image1, image2) {
const detections1 = await detectFace(image1);
const detections2 = await detectFace(image2);
if (!detections1 || !detections2) {
return false; // No face detected
}
const distance = faceapi.euclideanDistance(
detections1.descriptor, detections2.descriptor
);
const MATCH_THRESHOLD = 0.6; // Set an appropriate threshold
return distance < MATCH_THRESHOLD; // If distance is below the threshold, the faces match
}