-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFisherFaceRecognizer.py
More file actions
50 lines (35 loc) · 1.23 KB
/
FisherFaceRecognizer.py
File metadata and controls
50 lines (35 loc) · 1.23 KB
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
import cv2
import os
import numpy as np
subjects = ["", "kejriwal", "modi"]
def prepare_training_data(data_folder_path):
dirs = os.listdir(data_folder_path)
faces = []
labels = []
label = 1
for dir_name in dirs:
subject_dir_path = data_folder_path + "/" + dir_name
subject_images_names = os.listdir(subject_dir_path)
for image_name in subject_images_names:
image_path = subject_dir_path + "/" + image_name
image = cv2.imread(image_path)
image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
image = cv2.resize(image, (150,150))
cv2.imshow("Training on image...", cv2.resize(image, (400, 500)))
cv2.waitKey(100)
faces.append(image)
labels.append(label)
label += 1
cv2.destroyAllWindows()
cv2.waitKey(1)
cv2.destroyAllWindows()
return faces, labels
print("Preparing data...")
faces, labels = prepare_training_data("data_noresize")
print("Data prepared")
#print total faces and labels
print("Total faces: ", len(faces))
print("Total labels: ", len(labels))
face_recognizer = cv2.face.FisherFaceRecognizer_create()
face_recognizer.train(faces, np.array(labels))
face_recognizer.write('res.yml')