Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #importing libraries
- import face_recognition
- import os
- #method for encoding the image
- #it takes path as argument, which is the address of the photo we want to encode
- def encoding(path):
- image = face_recognition.load_image_file(path)
- imageEncoding = face_recognition.face_encodings(image)[0]
- return imageEncoding
- #this mehod is for comparing the photo from unkwon folder with all photos in known folder
- #it takes 2 arguments, unkownPerson is the path of photo in unknown folder, while nameOfPerson is simple name of photo
- def compare(unkownPerson,nameOfPerson):
- isAttendant = False #it's used to check if the photo from unkown folder is already in known folder
- for image in os.listdir('/Users/yermukhanbet/PycharmProjects/dataBase/venv/lib/python3.7/known'): #iterates through photos in the known folder
- if image == '.DS_Store': #checks if the image is the hidden file ".DS_Store" and if yes then it passes and goes to the next file in the folder
- continue
- else:
- known_image_path = '/Users/yermukhanbet/PycharmProjects/dataBase/venv/lib/python3.7/known/'+image
- result = face_recognition.compare_faces([encoding(known_image_path)],encoding(unkownPerson), tolerance=0.45)
- print(image, str(result))
- if result[0] == True:
- print("Your face matched! You're attended")
- os.remove(unkownPerson)
- isAttendant = True
- break
- if isAttendant == False:
- print("You're added successfully!")
- os.rename(unkownPerson, "/Users/yermukhanbet/PycharmProjects/dataBase/venv/lib/python3.7/known/"+nameOfPerson)
- def mainCompare():
- if len(os.listdir('/Users/yermukhanbet/PycharmProjects/dataBase/venv/lib/python3.7/unknown')) - 1 == 0:
- print("There are no pictures")
- else:
- for image in os.listdir('/Users/yermukhanbet/PycharmProjects/dataBase/venv/lib/python3.7/unknown'):
- if image == '.DS_Store':
- continue
- else:
- return compare('/Users/yermukhanbet/PycharmProjects/dataBase/venv/lib/python3.7/unknown/' + image, image)
- mainCompare()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement