diff options
Diffstat (limited to 'face-detection/02_face_training.py')
-rw-r--r-- | face-detection/02_face_training.py | 7 |
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)))) |