Sign In

Face Cropper - tool to automatically crop the faces from photos

Face Cropper - tool to automatically crop the faces from photos

Hello Everyone!

I promised to release that script last weekend but I was too tired to do so, never-the-less - here it is. Sorry for the delay!

Link to the repo: https://github.com/malcolmamal/face-cropper

So, how does this work? Let's see the results first:

Edit: link to the full image: https://i.imgur.com/Ua4RcCy.png

On the right side, I have the source images downloaded using BID (Bulk Image Downloader) that were manually hand-picked by myself (when I download images from searches like google or duckduckgo image search - I have to pick the ones that represent the given person and are quite good, for example - face is clearly visible)

Then I run the script (you can run it via run.bat or just check what is there and update accordingly).

The result is what you see on the left side.

The script goes through every source image and tries to locate the face and then it crops it to a square. I have to expand it a bit because the library focuses mainly on the eyes and mouth and we want the full head. Since this is an automated process I have several presets so from one source image we receive one to five cropped variations.

So, after cropping, I browse it with my TotalCommander and select the variation that fits best.

Currently, the script supports all square resolutions but I've tested it only on 512x512, 768x768, and 1024x1024.

Images can be in various formats (I usually do jpegs, pngs and webp but I assume the library can handle most of the common formats).

When cropping to 512x512 I discard all images that have lower resolution, however when we are cropping to 768 or 1024 - if the image is at least 512x512 resolution (but below the destination resolution) the script will do an upscale (since it is sometimes more difficult to find photos that are big enough).

Besides the resolution, there are other params to run the script with (use the -h to prompt the help, or just look at the github page - all the options are listed and explained)

I will be most likely updating the script, so if you have some feature suggestions - go right ahead :)

I suppose the two most requested features might be non-square resolutions (like 512x768 and so on) and different cropping options (not only facial shots but also face + torso or even full body shots). All of that is possible, I just didn't need it yet so I focused mainly on the faces :)

It is best to have a single person in the photo, although I'm already working on the feature where it finds the proper face to crop if there is more than one person in the photo.

!!! WARNING !!! -> There is one "big" hurdle with this script, one of the libraries that is needed - is a FUCKING pain in the ass to install. It is the DLIB library. If you already have it - great, but if not - by default it might automatically install itself without CUDA support. No worries, though - I have linked on the github page tutorials how to install it with CUDA support on Windows. It helped me so you can also do it :>

With the CUDA support one image is processed in around 2-3 seconds, without it - it uses CPU and you have to wait a minute or so for an image. (Might be okay when you set it up for a night, but for normal flow - I would say it is better to go through the pain and install it with CUDA support!).

If there is a need, I can make a tutorial for installing DLIB with Cuda support, I have a machine where I could install it so I could do that and document the process. But without the external need - I'm not really feeling like I need to :>

p.s. besides that - the install process should be straightforward, everything is listed on the github page - but if you experience some issues -> please leave a comment with the error message and we will power through that together :)

p.s.s. I've also made an update post on my buymeacoffee page about what models were recently done and which models will be done soon: https://www.buymeacoffee.com/malcolmrey/22-new-lycoris-54-loras

36

Comments