Search code examples
python-3.xface-recognition

How to make face_recognition get right face number?


Please download the image and save it as test.png.

download and save it as test.png

Everyone can see that there are two person in it,each one has a whole face.
Let python code count the face number in the image.

from PIL import Image
import face_recognition
image = face_recognition.load_image_file('test.png')
face_locations = face_recognition.face_locations(image)
print("I found {} face(s) in this photograph.".format(len(face_locations)))

Output :

I found 1 face(s) in this photograph.

How to make face_recognition get right face number?


Solution

  • You can try

    face_locations = face_recognition.face_locations(image, number_of_times_to_upsample=2, model="cnn")
    

    It will work longer but more accurate then default "hog" model and the only one upsample run.