summaryrefslogtreecommitdiff
path: root/face-detection/02_face_training.py
diff options
context:
space:
mode:
authorSaumit Dinesan <justsaumit@protonmail.com>2023-04-22 23:23:31 +0530
committerSaumit Dinesan <justsaumit@protonmail.com>2023-04-22 23:23:31 +0530
commit4633e624fdc4e61928b8c7743d9bbd50c5d75a6a (patch)
treea70cb02e96274176785e04e309b059401bc69298 /face-detection/02_face_training.py
parent95b861dc16d1a29200734fb42f4f4223d14d12f1 (diff)
face-detection cleanup+Adding .gitignore
Diffstat (limited to 'face-detection/02_face_training.py')
-rw-r--r--face-detection/02_face_training.py7
1 files changed, 4 insertions, 3 deletions
diff --git a/face-detection/02_face_training.py b/face-detection/02_face_training.py
index 938761b..68b21fe 100644
--- a/face-detection/02_face_training.py
+++ b/face-detection/02_face_training.py
@@ -6,8 +6,8 @@ import os
path = 'dataset'
# Using LBPH(Local Binary Patterns Histograms) recognizer
recognizer = cv2.face.LBPHFaceRecognizer_create()
-detector = cv2.CascadeClassifier("haarcascade_frontalface_default.xml");
-# function to get the images and label data
+detector = cv2.CascadeClassifier("haarcascade_frontalface_default.xml"); #create an instance
+# function to read the images in the dataset, convert them to grayscale values, return samples
def getImagesAndLabels(path):
imagePaths = [os.path.join(path,f) for f in os.listdir(path)]
faceSamples=[]
@@ -24,8 +24,9 @@ def getImagesAndLabels(path):
print ("\n [INFO] Training faces. It will take a few seconds. Wait ...")
#returns two arrays faces and ids
faces,ids = getImagesAndLabels(path)
+#Train the LBPH recognizer using the face samples and their corresponding labels
recognizer.train(faces, np.array(ids))
#save the model into trainer/trainer.yml
recognizer.write('trainer/trainer.yml')
-# Print the numer of faces trained and end program
+# Print the numer of faces trained and then exit the program
print("\n [INFO] {0} faces trained. Exiting Program".format(len(np.unique(ids))))