Skip to content

Instantly share code, notes, and snippets.

@smitshilu
Last active March 28, 2021 16:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save smitshilu/4e47477d6d504166786fb004df638b9d to your computer and use it in GitHub Desktop.
Save smitshilu/4e47477d6d504166786fb004df638b9d to your computer and use it in GitHub Desktop.
dlib face landmark comparison example
# 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