0

I want to sort many face images to make good face images data. So, I want there's no blur, no multiple faces in one image in my images data.

I've tried the code, but my code just can check single image at once

image = face_recognition.load_image_file("./pictures/image.jpg")
face_locations = face_recognition.face_locations(image)
print(face_locations)

Is there any code to make my code can detect multiple images at once? I'd appreciate any answer. Thanks in advance!

Roman Patutin
  • 2,171
  • 4
  • 23
  • 27
farhanrbn
  • 13
  • 3

2 Answers2

0

There are no API calls in face_recognition, that allows loading several images in on time.
This page with the API documentation at readthedocs.

So I think you have to load the list of the images from a directory and then use it in a loop to get images objects.

This is This is great SO thread with answer how to load the list of files from directory using Python: Find all files in a directory with extension .txt in Python

Roman Patutin
  • 2,171
  • 4
  • 23
  • 27
0

I have no idea which framework or library you are using and you are not specific either. As tags suggest I will do it in pythonic way.

Walk over the current directory and find and filter files by extension.

import os

def getfiles():
    for root, dirs, files in os.walk("."):
        for name in files:
            yield os.path.join(root, name)

files = filter(lambda image: (image[-3:] == '.jpg' or image[-3:] == '.png'), getfiles())

# now you can loop your image detection api call.
for file in files
    image = face_recognition.load_image_file(file)
    face_locations = face_recognition.face_locations(image)
    print(face_locations)
Debendra
  • 1,132
  • 11
  • 22