Simple utility based on face recognition to crop out a given face out of multiple pictures.
The idea is that, if you need to make a dataset with someone's face cropped out properly, it can be very long to do it by hand. The goal is to automate this action.
This utility takes all of the images in a folder, recognizes the input face in the images, crops the pictures and saves them in another folder. It works even when there are several people in the pictures.
This utility is almost entirely based on the face-recognition package.
Leveraging Google Photos' face grouping feature, to bunk download all of the pictures of a given person, and training a GAN to generate realistic faces. It could now be used today to create a database to fine-tune Stable Diffusion with Dreambooth for example.
For example, it will take this image:
And using the encoding of this image:
It will output this one:
This utility was made for Python 3.10 and Linux (or WSL-2 on Windows) and was not tested on other versions or systems.
git clone https://github.com/ArthurVerrez/bulk-face-cropping.git
cd bulk-face-cropping
python3 -m venv venv
source venv/bin/activate
pip install -r requirements.txt
The installation of face_recognition might take a while because it has to build dlib from source.
python3 extract_faces.py -i <input_folder> -o <output_folder> -f <face_refence_image>
You can also add -v for verbose mode.
The <face_reference_image> file must only contain one face.
python3 extract_faces.py -i demo_images/input -o demo_images/output -f demo_images/ref_image.jpg
Enjoy!