DEV Community

Discussion on: Going through 10,000 pictures in 30 seconds

Collapse
 
codingmona profile image
codingmona

Hello,

Thank you so much for this wonderful script. I have tried it multiple times and unfortunately it's not working for me. I always end up with "No match found!". Can you please take a quick look on my script and let me know if there is anything wrong?

import face_recognition
import copyfile
import shutil
from PIL import Image

Create an encoding of my facial features that can be compared to other faces

picture_of_me = face_recognition.load_image_file("/Pathtomyphoto/CynthiaDavisHall.jpg")
my_face_encoding = face_recognition.face_encodings(picture_of_me)[0]

Iterate through all the 10,460 pictures

import os
files = os.listdir('/Pathtoallphotosfolder')
for file in files:
file_name = os.path.join('/Pathtoallphotosfolder/', file)
print(file_name)

Load this picture

new_picture = face_recognition.load_image_file(file_name)
face_encoding = face_recognition.face_encodings(new_picture)[0]

# Iterate through every face detected in the new picture
for face_encoding in face_recognition.face_encodings(new_picture):

    # Run the algorithm of face comaprison for the detected face, with 0.5 tolerance
    results = face_recognition.compare_faces([my_face_encoding], face_encoding, 0.5)

    # Save the image to a seperate folder if there is a match

if results[0] == True:
copyfile(file_name, "/pathtonewlocation/" + file_name)
else:
print("No match found!")

Collapse
 
phpsaux profile image
Roger Santos

didn't work for me too