I'm including facial recognition in my Electron app using Node.js and I would like to know if I'm doing the process correctly, as I was a little confused by some points in the documentation.
I'm using the aws-sdk
library and I want that, when taking a picture of the user, my system searches for him in the database of faces registered in Rekognition and returns me who this user is - that is, his userId
in my MySQL database.
I've already created a Collection
called "Users" and I would like to know how to inform the userId
to the indexFaces
method. Initially, I intend to allow the inclusion of only one photo per user and I'm currently doing it like this:
const params = {
CollectionId: 'Users',
Image: { Bytes }, // The image in base64
ExternalImageId: '1', // The userId in MySQL
MaxFaces: 1,
QualityFilter: 'HIGH'
};
Rekognition.indexFaces(params, (err, data) => {
if (err) {
console.log(err, err.stack);
return;
}
console.log(data);
});
The entire face registration process works normally and the code I use to search for the faces already registered is:
const params = {
CollectionId: 'Users',
Image: { Bytes }, // The image in base64
MaxFaces: 1,
FaceMatchThreshold: 99
};
Rekognition.searchFacesByImage(params, (err, data) => {
if (err) {
console.log(err, err.stack);
return;
}
for (let i = 0; i < data.FaceMatches.length; i ) {
console.log(data.FaceMatches[i].Face);
}
});
If the consulted face is registered and found in the Collection
, the value returned is:
{
FaceId: 'b7506fc1-e8...',
BoundingBox: {...},
ImageId: 'e11d94c1-831...',
ExternalImageId: '1', // `userId` in my MySQL as desired
Confidence: 99.999...,
IndexFacesModelVersion: '6.0'
}
My question is: am I associating the userId
with the face correctly through the ExternalImageId
property or should I do it in a more appropriate way? If yes, how?
CodePudding user response:
Yes, that is the purpose of the ExternalImageId
field -- it is for you to associate your own reference to the face. You are doing it correctly (assuming that the code works).