Advertisement
Guest User

Untitled

a guest
Oct 17th, 2019
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.74 KB | None | 0 0
  1. #!/usr/bin/python3
  2.  
  3. # Import libraries.
  4. from PIL import Image
  5. import numpy as np
  6. import cv2
  7. import os
  8.  
  9. # Clear screen.
  10. os.system("clear")
  11.  
  12. # Print info.
  13. print("[INFO] OpenCV running on v." + cv2.__version__)
  14. print("[INFO] Classifier the face...")
  15.  
  16. # Main code.
  17. def trainClassifier(dataPath):
  18. path = [os.path.join(dataPath,f) for f in os.listdir(dataPath)]
  19. faces = []
  20. ids = []
  21.  
  22. for image in path:
  23. img = Image.open(image).convert("L")
  24. imageNp = np.array(img, 'uint8')
  25. id = int(os.path.split(image)[1].split(".")[1])
  26. faces.append(imageNp)
  27. ids.append(id)
  28.  
  29. ids = np.array(ids)
  30.  
  31. clf = cv2.face.LBPHFaceRecognizer_create()
  32. clf.train(faces, ids)
  33. clf.write("classifierCache.xml")
  34.  
  35. trainClassifier("dataset")
  36.  
  37. print("\n\n[INFO] Closing All Process")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement