-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtrainer.py
More file actions
36 lines (29 loc) · 883 Bytes
/
trainer.py
File metadata and controls
36 lines (29 loc) · 883 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# import the libraries
import cv2
import os
import numpy as np
from PIL import Image
recognizer = cv2.createLBPHFaceRecognizer()
path = 'dataSet'
def getImagesID(path):
imagePaths = [os.path.join(path,f) for f in os.listdir(path)]
faces = []
IDs = []
# names = []
for ImagePath in imagePaths:
faceImage = Image.open(ImagePath).convert('L')
faceNp = np.array(faceImage,'uint8')
ID = int(os.path.split(ImagePath)[-1].split('.')[1])
# name = os.path.split(ImagePath)[-1].split('.')[3]
print ID
# print name
faces.append(faceNp)
IDs.append(ID)
# names.append(name)
cv2.imshow("Windows",faceNp)
cv2.waitKey(10)
return np.array(IDs), faces
Ids, faces = getImagesID(path)
recognizer.train(faces,Ids)
recognizer.save('recognizer/trainingData.yml')
cv2.destroyAllWindows()