-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathTrain.py
38 lines (30 loc) · 895 Bytes
/
Train.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
import os
import pandas as pd
import numpy as np
import cv2 as cv
id_names = pd.read_csv('id-names.csv')
id_names = id_names[['id', 'name']]
lbph = cv.face.LBPHFaceRecognizer_create(threshold=500)
def create_train():
faces = []
labels = []
for id in os.listdir('faces'):
path = os.path.join('faces', id)
try:
os.listdir(path)
except:
continue
for img in os.listdir(path):
try:
face = cv.imread(os.path.join(path, img))
face = cv.cvtColor(face, cv.COLOR_BGR2GRAY)
faces.append(face)
labels.append(int(id))
except:
pass
return np.array(faces), np.array(labels)
faces, labels = create_train()
print('Training Started')
lbph.train(faces, labels)
lbph.save('Classifiers/TrainedLBPH.yml')
print('Training Complete!')