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.

The requirements.txt file lists the Python packages Facer depends on. Install the packages using pip:

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.

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

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

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.6.0.tar.gz (8.5 kB view details)

Uploaded Source

Built Distribution

average_facer-0.6.0-py3-none-any.whl (9.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: average_facer-0.6.0.tar.gz
  • Upload date:
  • Size: 8.5 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.6.0.tar.gz
Algorithm Hash digest
SHA256 9baa20b330178c2e62fadf7b6af67b3ce8797b59e4262bcea61625e3cd4ed247
MD5 c5d59d5a09850ed9fb02eed02aa1c6ad
BLAKE2b-256 9823a2d4e3d784f1d1b6728e6d4dbce312a4d146e23030bf1e4609531bab0bc2

See more details on using hashes here.

File details

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

File metadata

  • Download URL: average_facer-0.6.0-py3-none-any.whl
  • Upload date:
  • Size: 9.5 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.6.0-py3-none-any.whl
Algorithm Hash digest
SHA256 3ea6b992562185d49dd175c8b41501077e8ff8db9f61e49971210a299fb28ffe
MD5 436d5c8b942c787e061bf07c8101e99c
BLAKE2b-256 eb169918186dd444218e3765fa871dad3837c32942df6ac4d64a4f1029c74a08

See more details on using hashes here.

Supported by

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