Skip to content

Simple utility using face recognition to crop out a given face out of multiple pictures.

License

Notifications You must be signed in to change notification settings

ArthurVerrez/bulk-face-cropping

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Bulk Face Cropping

Overview

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.

Motivation

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.

Example

For example, it will take this image: Meghan Markle and prince Harry

And using the encoding of this image: Meghan Markle's face

It will output this one:

Meghan Markle's face cropped

Installation

Requirements

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.

Usage

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.

Example usage

python3 extract_faces.py -i demo_images/input -o demo_images/output -f demo_images/ref_image.jpg

Enjoy!

About

Simple utility using face recognition to crop out a given face out of multiple pictures.

Topics

Resources

License

Stars

Watchers

Forks

Languages