I am currently creating a facial recognition system using this API: https://github.com/justadudewhohacks/face-api.js/
Reference: https://blog.mdzulkarnine.com/building-face-recognition-api-with-nodejs-expressjs-mongodb-face-apijs
In client-side, after successful detection of the face it will fetch post request to the server and send the resizedDetection
$("#face").attr("src",img_data);
const input = await $('#face')[0];
const detection = await faceapi.detectAllFaces(input).withFaceLandmarks().withFaceDescriptors();
const resized = await faceapi.resizeResults(detection, displaySize);
if(!fetched && resized) {
fetched = true;
await fetch('/establishment/verify', {
method: 'POST',
headers: {
"content-type": "application/json"
},
body: JSON.stringify({ resized })
// descriptor
})
.then((response)=> {
console.log(response);
});
}
In the server, it will accept the resizedDetection from the client-side.
const verification_post = async (req, res) => {
try {
const resizedDetections = req.body.resized;
let visitors = await Visitor.find();
for(i=0;i<visitors.length;i++) {
for (j = 0; j < visitors[i].descriptions.length; j++) {
visitors[i].descriptions[j] = new Float32Array(Object.values(visitors[i].descriptions[j]));
}
visitors[i] = new faceapi.LabeledFaceDescriptors(visitors[i]._id.toString(), visitors[i].descriptions);
}
const faceMatcher = new faceapi.FaceMatcher(visitors, 0.6);
console.log("Faces: ", visitors);
console.log("Resized Detections: ", resizedDetections);
const results = resizedDetections.map((des) => faceMatcher.findBestMatch(des.descriptor));
} catch (error) {
console.log(error);
res.status(400).send(error);
}
}
The visitors and resizedDetection is displaying correctly, but it is not proceeding to the part of results, and returning the error "Error: euclideanDistance: arr1.length !== arr2.length". Is there anyone who tried working with it?