Advertisement
Guest User

Untitled

a guest
Dec 11th, 2019
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.87 KB | None | 0 0
  1. #importing libraries
  2. import face_recognition
  3. import os
  4. from Student import Student
  5. from datetime import datetime
  6.  
  7.  
  8. #method for encoding the image
  9. #it takes path as argument, which is the address of the photo we want to encode
  10. def encoding(path):
  11. image = face_recognition.load_image_file(path)
  12. imageEncoding = face_recognition.face_encodings(image)[0]
  13. return imageEncoding
  14.  
  15.  
  16. #this mehod is for comparing the photo from unkwon folder with all photos in known folder
  17. #it takes 2 arguments, unkownPerson is the path of photo in unknown folder, while nameOfPerson is simple name of photo
  18. def compare(unkownPerson,nameOfPerson):
  19. isAttendant = False #it's used to check if the photo from unkown folder is already in known folder
  20. for image in os.listdir('/Users/yermukhanbet/PycharmProjects/dataBase/venv/lib/python3.7/known'): #iterates through photos in the known folder
  21. 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
  22. continue
  23. else:
  24. known_image_path = '/Users/yermukhanbet/PycharmProjects/dataBase/venv/lib/python3.7/known/'+image
  25. result = face_recognition.compare_faces([encoding(known_image_path)],encoding(unkownPerson), tolerance=0.45)
  26. print(image, str(result))
  27. if result[0] == True:
  28. print("Your face matched! You're attended")
  29. os.remove(unkownPerson)
  30. isAttendant = True
  31. break
  32. if isAttendant == False:
  33. print("Oops, it seems that you are not in this class!")
  34. id = input("enter your id ")
  35. os.rename(unkownPerson, "/Users/yermukhanbet/PycharmProjects/dataBase/venv/lib/python3.7/known/"+str(id)+".jpg")
  36. addNewStudentToList(id)
  37. print("You're added successfully!")
  38.  
  39. def addNewStudentToList(id):
  40. firstName = input("Enter your first name: ")
  41. lastName = input("Enter your last name: ")
  42. checkInTime = getTheCurrentTime()
  43. newStudent = Student(firstName,lastName,id,checkInTime)
  44. listOfStudents.append(newStudent)
  45.  
  46. def getTheCurrentTime():
  47. now = datetime.now()
  48. currentTime = now.strftime("%H:%M:%S")
  49. return currentTime
  50.  
  51. def printPresentStudents():
  52. for student in listOfStudents:
  53. print(student)
  54.  
  55. def mainCompare():
  56. if len(os.listdir('/Users/yermukhanbet/PycharmProjects/dataBase/venv/lib/python3.7/unknown')) - 1 == 0:
  57. print("There are no pictures")
  58. else:
  59. for image in os.listdir('/Users/yermukhanbet/PycharmProjects/dataBase/venv/lib/python3.7/unknown'):
  60. if image == '.DS_Store':
  61. continue
  62. else:
  63. return compare('/Users/yermukhanbet/PycharmProjects/dataBase/venv/lib/python3.7/unknown/' + image, image)
  64.  
  65.  
  66. listOfStudents = []
  67. mainCompare()
  68.  
  69. printPresentStudents()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement