justadudewhohacks / face-api.js

JavaScript API for face detection and face recognition in the browser and nodejs with tensorflow.js
MIT License
16.53k stars 3.69k forks source link

Compare and match same face in an image #489

Open sibithabijesh opened 4 years ago

sibithabijesh commented 4 years ago

Hello,

I am trying to compare two faces in the same image and find the match. Could you please let me know how do I achieve this by using detectAllFaces method.

TonySpegel commented 4 years ago

The Key to recognize Faces lays in comparing their Descriptors. These 128 Values represent the, as far as I can tell, the Landmarks of a Face - so the Postion of your Nose, your Eyes and so on.

Read this section to know what it is about and how to use it. Using FaceMatcher is basically comparing two Descriptors which also happen to have a Label. There's also the Euclidean Distance, which tells you - more or less the overall Distance of Points/Landmarks in an Image. So the farther away from the Value 0 the less likely it is that it is the same Person - and there's a Treshold of about 0.66 which tells you that it's most liely not the same Person.

Hope that helps?

justadudewhohacks commented 4 years ago

The Key to recognize Faces lays in comparing their Descriptors. These 128 Values represent the, as far as I can tell, the Landmarks of a Face - so the Postion of your Nose, your Eyes and so on.

Just want to clearify something here, since this confuses a lot of people. The face descriptor does not have anything to do with the face landmarks. The face landmarks are comprised by 68 points (so it is a vector of length 136 comprising x and y values. The landmarks and the descriptor are produces by two different models.

I am trying to compare two faces in the same image and find the match. Could you please let me know how do I achieve this by using detectAllFaces method.

Get all faces in the image with their corresponding descriptors and than compare the descriptors pairwise by computing the euclidean distance.

sibithabijesh commented 4 years ago

I am trying to find the faces in the selfie image holding their id card. but I got only one descriptors array from the below code. Could you please let me know whats the issue

 const resultSelfie = await faceapi
    .detectAllFaces(selfie, getFaceDetectorOptions(faceDetectionNet))
    .withFaceLandmarks()
    .withFaceExpressions()
    .withFaceDescriptors(); 
justadudewhohacks commented 4 years ago

If you only get one object back from the API call, than the face detector was able to find one face only in your image.

sibithabijesh commented 4 years ago

But my image have 2 face (Selfie _+ ID card) . Is there any specific resolution for the uploaded image

justadudewhohacks commented 4 years ago

You can try out different face detector options, first you can try to employ SSDMobilenetv1, which is the most accurate method currently. Another option would be to try out the TinyFaceDetector and tune the input size parameter.