Face detection, alignment, and averaging using OpenCV and
You have my 100% money-back guarantee that the most difficult part of using this package is installing its requirements. Once you've got OpenCV installed, the rest will be smooth sailing.
On Mac, use
homebrew to install OpenCV. On Windows, I have no clue. Sorry.
brew install opencv
brew to install OpenCV did actually work for me, but it also broke my previous Python installation and all my virtual environments. So uhh, good luck with that.
After installing OpenCV, use
pip to install
numpy from the
pip install -r requirements.txt
Pre-trained detection model
The face landmark detection relies on a pre-trained model that must be downloaded separately from the
dlib package itself.
Unzip the compressed file after it finishes downloading and move it into the
from facer import facer # Load face images path_to_images = "./face_images" images = facer.load_images(path_to_images) # Detect landmarks for each face landmarks, faces = facer.detect_face_landmarks(images) # Use the detected landmarks to create an average face average_face = facer.create_average_face(faces, landmarks, save_image=True) # View the composite image plt.imshow(average_face) plt.show()
Facer also supports creating animated GIFs of the averaging process:
from facer import facer path_to_images = "./face_images" gif, average_face = facer.create_animated_gif(path_to_images)