-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtrainer.py
42 lines (25 loc) · 820 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
41
42
import cv2
import sys
import numpy
import os
# Training recognizer
print "Training..."
(images, labels, names, id) = ([], [], {}, 0)
for (subdirs, dirs, files) in os.walk('att_faces'):
for subdir in dirs:
names[id] = subdir
subpath = os.path.join('att_faces', subdir)
for filename in os.listdir(subpath):
path = subpath + '/' + filename
label = id
images.append(cv2.imread(path, 0))
labels.append(int(label))
id += 1
print names
(img_width, img_height) = (112, 92)
(images, labels) = [numpy.array(l) for l in [images, labels]]
model = cv2.createFisherFaceRecognizer()
# model = cv2.createEigenFaceRecognizer()
# model = cv2.createLBPHFaceRecognizer()
model.train(images, labels)
model.save('face_recognizer_model.xml')