This Python script automates the processing of a batch of images by detecting faces and ensuring they are correctly aligned (facing the camera). It is designed for applications that require consistent facial orientation in images, such as identity verification systems or profile picture processing. Given a batch of pictures, the script ensures all output images have the subject centered. Photos without a face, not looking at the camera, or with multiple subjects, will be discarded and placed in the output/trash
folder.
- Face Detection: Uses the
face_recognition
library to identify faces in images. - Facial Landmarks Identification: Detects key facial landmarks to determine face orientation.
- Orientation Check: Determines whether the subject is looking directly at the camera.
- Confidence Scoring: Provides a confidence score for the face orientation assessment.
- Image Cropping and Resizing: Adjusts images based on the position of the detected face, maintaining a specific aspect ratio and size.
- Batch Processing: Capable of processing multiple images in various formats (PNG, JPG, JPEG, TIFF, BMP, GIF).
- Organized Output: Saves processed images in an
output
folder and moves non-conforming images tooutput/trash
.
This script is a work in progress and far from perfect. Users should anticipate some inconsistencies and limitations in its current form.
- Mini Image Saving Issue: Images with
xxx_mini.jpg
extensions are sporadically saved, although they are meant only for processing and should not be saved. - Skipping/Duplicating Images: There are instances where pictures are sometimes skipped and sometimes duplicated in the output.
- Algorithm Reliability: The algorithm is not fully reliable, and results should be manually verified for accuracy.
- Python 3.x
- Libraries:
face_recognition
,PIL
(Pillow),numpy
,shutil
,os
- You can install them with
pip install -r requirements.txt
- Place the images you want to process in the
input_folder
. - Run the script.
- Processed images will appear in the
output_folder
. Images not meeting the criteria will be in theoutput/trash
folder.
- Merging the script with the duplicates detection.
- Bug-fixing
[Leandro Piccione]