-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtrain_model.py
More file actions
64 lines (48 loc) · 946 Bytes
/
Copy pathtrain_model.py
File metadata and controls
64 lines (48 loc) · 946 Bytes
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import cv2
import os
import numpy as np
recognizer = cv2.face.LBPHFaceRecognizer_create()
faces = []
labels = []
people = {
"devi": 0,
"mama": 1,
"dada": 2
}
for person_name, label in people.items():
person_path = os.path.join(
"faces",
person_name
)
if not os.path.exists(person_path):
continue
for image_name in os.listdir(person_path):
image_path = os.path.join(
person_path,
image_name
)
img = cv2.imread(
image_path,
cv2.IMREAD_GRAYSCALE
)
if img is None:
continue
img = cv2.resize(
img,
(200, 200)
)
faces.append(img)
labels.append(label)
print(
f"Training on {len(faces)} images"
)
recognizer.train(
faces,
np.array(labels)
)
recognizer.save(
"trainer.yml"
)
print(
"Multi-user model trained!"
)