You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

34 lines
1007 B

6 years ago
  1. import os
  2. import sys,getpass
  3. import json
  4. import base64
  5. import face_recognition
  6. import utils
  7. with open('databases/users.json') as f:
  8. users = json.load(f)
  9. for file in os.listdir("../images"):
  10. if file.endswith(".png") or file.endswith(".jpg"):
  11. uid = file.split('.')[0]
  12. if len(uid) == 32 and utils.find_by_id(users.values(), uid):
  13. full_path = os.path.join("../images", file)
  14. image = face_recognition.load_image_file(full_path)
  15. with open(full_path, 'rb') as f:
  16. base64_image = base64.b64encode(f.read())
  17. if getpass.getuser() == "tedankara":
  18. face_locations = face_recognition.face_locations(image)[0]
  19. face_encoding = face_recognition.face_encodings(image)[0]
  20. for k in users.keys():
  21. if users[k]['id'] == uid:
  22. users[k]['image'] = base64_image.decode()
  23. users[k]['face_locations'] = face_locations
  24. users[k]['face_encoding'] = list(face_encoding)
  25. with open('databases/users.json', 'w') as f:
  26. users = json.dump(users, f, indent=2)
  27. os.remove(full_path)