-
Notifications
You must be signed in to change notification settings - Fork 0
/
train.py
39 lines (30 loc) · 955 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
39
import cv2
import os
import numpy as np
dataPath = r"C:\Users\AaronPC\Desktop\FarmaPlusPY\Fotos"
dir_list = os.listdir(dataPath)
print("Lista archivos:", dir_list)
labels = []
facesData = []
label = 0
for name_dir in dir_list:
dir_path = dataPath + "/" + name_dir
for file_name in os.listdir(dir_path):
image_path = dir_path + "/" + file_name
print(image_path)
image = cv2.imread(image_path, 0)
#cv2.imshow("Image", image)
#cv2.waitKey(10)
facesData.append(image)
labels.append(label)
label += 1
print("Etiqueta 0: ", np.count_nonzero(np.array(labels) == 0))
print("Etiqueta 1: ", np.count_nonzero(np.array(labels) == 1))
# LBPH FaceRecognizer
face_mask = cv2.face.LBPHFaceRecognizer_create()
# Entrenamiento
print("Entrenando...")
face_mask.train(facesData, np.array(labels))
# Almacenar modelo
face_mask.write("data_faces.xml")
print("Modelo almacenado")