-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtrainModel.py
31 lines (22 loc) · 858 Bytes
/
trainModel.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
# -*- coding: utf-8 -*-
__author__ = 'Jasper Xu'
import numpy as np
import getData
import cv2
try:
# use read-made LBPH trainer in opencv3+
recognizer = cv2.face.LBPHFaceRecognizer_create()
# get all users' face samples
num = input('How many users do you want to recognize? \n')
for i in range(int(num)):
print('Now get samples for user No.{} ...' .format(i))
data_dir = getData.get_data()
# get all images and labels
faces,labels = getData.read_data(data_dir)
print ("[INFO] Start training! Please wait...")
recognizer.train(faces, np.array(labels))
# write only work on desktop, not on raspi
recognizer.write('D:/SECRET/face/model/trainer.yml')
print("[INFO] Successful in training {} faces".format(len(np.unique(labels))))
except :
print('Error!')