ageitgey / face_recognition

The world's simplest facial recognition api for Python and the command line
MIT License
52.99k stars 13.45k forks source link

How to mapping image encoding based on folder name #718

Open flyingduck92 opened 5 years ago

flyingduck92 commented 5 years ago

Hello man,

I have a set of images of 1 person My Image structure is like this:

Database/  Person1 / 1.jpg
Database/  Person1 / 2.jpg
Database/  Person1 / 3.jpg
Database/  Person1 / 4.jpg
.... 
Database/  Person9 / 1.jpg
Database/  Person9 / 2.jpg
Database/  Person9 / 3.jpg
Database/  Person9 / 4.jpg

How to mapping all image based on the folder name? Because I have multiple images for 1 person. Thanks.

lucas-amin commented 5 years ago

I am not sure if I understood your problem, in my vision, you want to use multiple encodings from the same person for face recognition.

You could create multiple folders like:

Database/  Person1-1 / 1.jpg
Database/  Person1-2 / 2.jpg
Database/  Person1-3 / 3.jpg
Database/  Person1-4 / 4.jpg
.... 
Database/  Person9-1 / 1.jpg
Database/  Person9-2 / 2.jpg
Database/  Person9-3 / 3.jpg
Database/  Person9-4 / 4.jpg

Then, treat the results from compare_faces just the way you do with a single photo for each person, giving name matches like "Person1-1" to "Person1-9", for example.

When you are going to show or store the extracted name, use string split to extract the true name. For example, resulting in the original name "Person1". "Person1-1".split("-")[0]