Face recognition and face detection are not the same .Face detection detects a face in an image , whereas face recognition recognize the face ,that whether the face is X,Y or Z. For face recognition , we need two models .One is to return the facial landmarks in a image, and pass the facial landmarks to another model, which converts the landmarks to a 128D vector values , and it is converted to a numpy array for face recognition and stored in a file with the name of the person.
STEP 1:IMPORTING THE NECESSARY LIBRARIES
We need four libraries for this example.
face_recognition_models - this library contains the necessary models needed to get the facial landmarks and face encodings.
dlib- this library has a shape predictor function which is used to get the facial landmarks and also the face encodings
cv2 - here we use this library to convert our image to a numpy array.
pickle - used to store the list or anything to the local disk
STEP 2: GET THE MODEL
Now we use face recognition models library to get the pretrained models for facial landmarks and face encodings, and pass it to the dlib respective functions. Thus we have a two models ,namely
1.landmarks_predictor
2.face_encoder
STEP 3: GET THE FACE LOCATIONS
By using the the dlib pretrained function to locate face, we will get the face locations.
STEP 4: GET THE FACIAL LANDMARKS
by using the .landmarks_predictor ,we will get the facial landmarks of the face in image.
STEP 5: GET THE FACE ENCODINGS
By using the face_encoder ,we will get the encodings from the landmarks. This method will return a 128D Vector values.
STEP 6: STORE THE ENCDOING WITH LABEL TO LOCAL DISK
We will store the array with a label name(person name).