Last active
March 28, 2021 16:22
-
-
Save smitshilu/4e47477d6d504166786fb004df638b9d to your computer and use it in GitHub Desktop.
dlib face landmark comparison example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# load the required model for 68 points detection | |
predictor = dlib.shape_predictor("shape_predictor_68_face_landmarks.dat") | |
face_rec = dlib.face_recognition_model_v1('dlib_face_recognition_resnet_model_v1.dat') | |
# iterate through all the detected faces | |
if (len(face_locations) > 0): | |
for face_location in face_locations: | |
# get 68 points landmark | |
face_encoding = predictor(frame, face_location) | |
face_descriptor = face_rec.compute_face_descriptor(frame, face_encoding, 1) | |
# See if the face is a match for the known face(s) | |
match = list((np.linalg.norm(saved_face_descriptor - (np.array(face_descriptor)), axis=1))) | |
val, idx = min((val, idx) for (idx, val) in enumerate(match)) | |
name = "Unknown" | |
if (val < 0.6): | |
name = names[idx] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment