-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathTraining.py
29 lines (24 loc) · 832 Bytes
/
Training.py
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
import os,cv2
import numpy as np
from PIL import Image
recognizer = cv2.createLBPHFaceRecognizer();
path = 'Data1'
def img(path):
imgpaths = [os.path.join(path,f) for f in os.listdir(path)] #getting images path
#print imgpaths
faces=[]
users=[]
for imgpath in imgpaths:
faceimg = Image.open(imgpath).convert('L') #converting to grayscale
facenp = np.array(faceimg,'uint8')
user=int(os.path.split(imgpath)[-1].split('.')[0]) #getting image ids
faces.append(facenp)
print user
users.append(user)
#cv2.imshow("Traning",facenp)
cv2.waitKey(10)
return users,faces
users , faces = img(path)
recognizer.train(faces,np.array(users)) #training
recognizer.save('TrainedDataFolder/TraningData.yml') #saving histogram data
cv2.destroyAllWindows()