Skip to main content

Face averaging in Python made simple.

Project description

Facer

Face detection, alignment, and averaging using OpenCV and dlib.

Facer draws heavily on this tutorial from Satya Mallick. I had to update the code pretty heavily to get the project to work, so I thought I'd share my modifications.

Example

The image below is an example of Facer's output for one of my posts on r/dataisbeautiful.

Average faces of rap, rock, and country music

Installation

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 should be smooth sailing. I've had the best luck with the OpenCV using the opencv-python package from PyPI.

Install facer using pip:

pip install -U average-facer

Pre-trained detection model

The face landmark detection relies on a pre-trained model that must be downloaded separately from the dlib package itself.

wget http://dlib.net/files/shape_predictor_68_face_landmarks.dat.bz2

Unzip the compressed file after it finishes downloading and move it into a ./model directory.

If you store the downloaded file somewhere other than ./model (or if you use an entirely different model name), you can set a custom model path as an environment variable:

export FACER_PREDICTOR_PATH="./custom/path/to/your/model.dat"

Usage

from facer import facer
import matplotlib.pyplot as plt


# Load face images
path_to_images = "./face_images"  # Put your images here
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)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

average_facer-0.7.6.tar.gz (11.6 kB view details)

Uploaded Source

Built Distribution

average_facer-0.7.6-py3-none-any.whl (11.8 kB view details)

Uploaded Python 3

File details

Details for the file average_facer-0.7.6.tar.gz.

File metadata

  • Download URL: average_facer-0.7.6.tar.gz
  • Upload date:
  • Size: 11.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.4 CPython/3.13.0 Darwin/23.6.0

File hashes

Hashes for average_facer-0.7.6.tar.gz
Algorithm Hash digest
SHA256 56898ed624ee6b9713e00b426132479e58e0c660d94eb9f1f906c8a3bdb7409e
MD5 ad70e3fe6e293bb90105bec269050751
BLAKE2b-256 72412a567232176b7b8399ed8d4ee119ecd2f5af49ba3a9d1ffac29df0711d9d

See more details on using hashes here.

File details

Details for the file average_facer-0.7.6-py3-none-any.whl.

File metadata

  • Download URL: average_facer-0.7.6-py3-none-any.whl
  • Upload date:
  • Size: 11.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.4 CPython/3.13.0 Darwin/23.6.0

File hashes

Hashes for average_facer-0.7.6-py3-none-any.whl
Algorithm Hash digest
SHA256 1d23d50927f581c46b001d73b354acb839880fb67376d584e8b918276eee6ed5
MD5 67f514aaad60c45fde32432a2415404f
BLAKE2b-256 1afa3850aff15913edfe6cde257677c14c2c772e770b3bcf7d19b4d9b1130821

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page