Python face_recognition multiple matches

63 Views Asked by At

I'm using python face_recongnition module. I want to recognise between 100 people and some faces are very similar. For example two brothers, both returns "True", both returns True for big brother and True for young brother.

I would like to know the most similar and only that returns true

I dont know what can I do to solve it

Thanks for any idea

    for caras in image_face_encoding:
     for known_face_encoding in [known_face_encodings]:

      matches = face_recognition.compare_faces(known_face_encoding, caras, tolerance=0.37)
      print(matches)                    

      name = "Unknow"

      if True in matches:
                    first_match_index = matches.index(True)
                    name = known_face_names[first_match_index]
                    contador=contador+1
                    print ('Encontrado!!! ', contador)
                    print(name)#input_image
1

There are 1 best solutions below

2
On

Solved!

A friend gave me the solution. "face_distances" is for know the numerical diference between the models and the image. Whith this i can know the most similar. The new code is:

  matches = face_recognition.compare_faces(known_face_encoding, caras, tolerance=0.40)##tolerance=image_thread## tolerance=0.45# tolerance=0.35

  face_distances = face_distances = face_recognition.face_distance(known_face_encoding, caras)##tolerance=image_thread## tolerance=0.45# tolerance=0.35
  name = "Unknow"
  best_match_index = np.argmin(face_distances)


  
  if True in matches:
                #first_match_index = matches.index(True)
                name = known_face_names[best_match_index]
                contador=contador+1
                print ('Encontrado!!! ', contador)
                print(name)#input_image