-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtrainer.py
40 lines (29 loc) · 911 Bytes
/
trainer.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
30
31
32
33
34
35
36
37
38
39
40
# -*- coding: utf-8 -*-
"""
Created on Tue Feb 25 15:02:46 2020
@author: yusuf
"""
import os
import numpy as np
import cv2
from PIL import Image
#####################CAREFUL#####################
recognizer = cv2.face.LBPHFaceRecognizer_create()
path = "Dataset"
def getUserPath(path):
imagePaths = [os.path.join(path,f) for f in os.listdir(path)]
faces = []
IDs = []
for imagePath in imagePaths:
faceImg = Image.open(imagePath).convert('L')
faceNp = np.array(faceImg,'uint8')
ID = int(os.path.split(imagePath)[-1].split('.')[1])
faces.append(faceNp)
IDs.append(ID)
cv2.imshow("training",faceNp)
cv2.waitKey(1)
return np.array(IDs), faces
Ids, faces = getUserPath(path)
recognizer.train(faces,Ids)
recognizer.save('recognizer/trainingData.yml')
cv2.destroyAllWindows()