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

Uploaded Source

Built Distribution

average_facer-0.6.2-py3-none-any.whl (9.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: average_facer-0.6.2.tar.gz
  • Upload date:
  • Size: 8.9 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.2.tar.gz
Algorithm Hash digest
SHA256 86da16b45e89b954350a77d9c895f5a746b84b71cf2ec8eff3099b985e36b7d0
MD5 9d8b61241593b793e303643ab4800650
BLAKE2b-256 3a297ff5b79be49895cef3f44b7f81363db2cf18dabe83a53ef212b3594d03cb

See more details on using hashes here.

File details

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

File metadata

  • Download URL: average_facer-0.6.2-py3-none-any.whl
  • Upload date:
  • Size: 9.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.6.2-py3-none-any.whl
Algorithm Hash digest
SHA256 ccf0a0c2e2b85b7c732103c20f457f925574d52c52e34f580b18b6bf5db9f515
MD5 1420b1a9e020ba87cbcec652f3034f58
BLAKE2b-256 2c87850fa9b9fb27c599c8c466833c91bb6a022ba76a777cf2120741822a0c9f

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