1
$\begingroup$

I have a fairly large dataset consisting of different images with and without persons that I want to use for a project.

The problem is that I only want the pictures that contain faces, and it is best if there is only a crop of the face.

I already looked at Facenet and Openface, but I thought that there must be a simpler already trained solution just to sort the dataset so I can get started with my own project.

$\endgroup$
  • $\begingroup$ You could try importing them into a photo management app; they often have face recognition built in to help you identify people in your pictures. $\endgroup$ – Oliver Mason May 20 '19 at 10:23
  • $\begingroup$ @OliverMason Thanks, but i have about 30k pictures which probably takes a long time to import :/ $\endgroup$ – AiRookie May 20 '19 at 10:31
1
$\begingroup$

I don't know of a tool but you could write a simple script to detect faces and crop it. It's quite simple with the Haar cascade in openCV to detect faces and use inbuilt functions to crop your image based on the size of the detected face.

Hope that helps !

| improve this answer | |
$\endgroup$
1
$\begingroup$

I have found a script that does what i need: https://github.com/leblancfg/autocrop

| improve this answer | |
$\endgroup$
1
$\begingroup$

I developed a python script to crop faces using MTCNN. I found this to be the most accurate of all the face cropping algorithms at the expense of being somewhat slower. The function I developed is on the kaggle website at https://www.kaggle.com/gpiosenka/detect-align-resize-rename-facial-images. The markup first cell explains how to use it. In a nutshell this function will crop the image files in the input directory and store them in an output directory. If there are multiple faces in an image it selects and crops the largest facial image. It also gives you the option to "align" the cropped images. By align I mean the cropped image is rotated so the eyes are horizontal. You also have the option to resize the cropped image. Finally you also have the option to rename the images in a numerically sequential order and to change the image format to one you specify. This is convenient because if you download images from the internet they have ungodly names and come in a vast variety of image formats. Also the function checks if any images are duplicates of each other. If duplicates are present a listing is provided and you can elect to delete duplicate images. Normally when you build a data set you want to eliminate duplicates so that if you split the data set into train, test and validation sets there is no "leakage" between the sets. I have used this function on thousands of images that have faces in them and it works extremely well. The cropped results are just what you want.On rare occasions a cropping error may occur so it is always wise to review the cropped results.

| improve this answer | |
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.