nischi / MMM-Face-Reco-DNN

Face recognition with opencv and deep neural network
MIT License
91 stars 46 forks source link

Select face name based on smallest distance #47

Closed paultranvan closed 4 years ago

paultranvan commented 4 years ago

This is a proposition to improve the name selection method.

The current method to find face matches is based on this method, that returns an array of boolean values. The associated name is retrieved for each true value ; then, the name with the highest match count is picked.

This approach tends to favor names with more encodings in the dataset, as they are more prone to match an encoding. For instance, let's say we have two names in the dataset, Alice and Bob, respectively with 100 and 10 face encodings, that are siblings, so quite look-alike. If Bob is in front of the mirror, he might have 10 matches (100% of his encodings), but Alice might also match for 20 encodings (20% of her encodings). Even though she is less "recognized", Alice will be picked.

To avoid this behavior, this PR base the name detection on the smallest distance: the chosen name is no longer the one with the more matches, but the one that has the closest encoding. It is both more reliable and more efficient, as there is less computation to make.

As a bonus, it also adds the tolerance parameter, to tune the face recognition sensitivity and display the distance next to the recognized name.

Hope you will like it!