Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/johnwmillr/facer
Simple (🤞) face averaging (🙂) in Python (🐍)
https://github.com/johnwmillr/facer
dlib face-average face-averaging face-detection facer image-processing opencv
Last synced: 5 days ago
JSON representation
Simple (🤞) face averaging (🙂) in Python (🐍)
- Host: GitHub
- URL: https://github.com/johnwmillr/facer
- Owner: johnwmillr
- License: mit
- Created: 2019-07-29T19:33:04.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2024-12-24T02:36:04.000Z (about 1 month ago)
- Last Synced: 2025-01-21T00:11:13.828Z (12 days ago)
- Topics: dlib, face-average, face-averaging, face-detection, facer, image-processing, opencv
- Language: Python
- Homepage:
- Size: 1.59 MB
- Stars: 80
- Watchers: 5
- Forks: 11
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
README
# Facer
Face detection, alignment, and averaging using OpenCV and `dlib`.
Facer draws heavily on [this tutorial](https://www.learnopencv.com/average-face-opencv-c-python-tutorial/) from [Satya Mallick](https://github.com/spmallick). 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`](https://www.reddit.com/r/dataisbeautiful/comments/crxrud/the_average_faces_of_rap_rock_and_country/).
[![Average faces of rap, rock, and country music](https://www.johnwmillr.com/assets/images/FaceAverages/Faces_RapRockCountry.png)](https://www.reddit.com/r/dataisbeautiful/comments/crxrud/the_average_faces_of_rap_rock_and_country/)
## 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`:
```bash
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.
```shell
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:
```bash
export FACER_PREDICTOR_PATH="./custom/path/to/your/model.dat"
```## Usage
```python
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:
```python
from facer import facerpath_to_images = "./face_images"
gif, average_face = facer.create_animated_gif(path_to_images)
```