# 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](assets/average_face_example.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.
The `requirements.txt` file lists the Python packages Facer depends on. Install the packages using `pip`:
```bash
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.
```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 the `./Facer/model` directory.
## 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 facer
path_to_images = "./face_images"
gif, average_face = facer.create_animated_gif(path_to_images)
```
Raw data
{
"_id": null,
"home_page": "https://github.com/johnwmillr/Facer",
"name": "average-facer",
"maintainer": null,
"docs_url": null,
"requires_python": "<4.0,>=3.9",
"maintainer_email": null,
"keywords": "opencv, image-processing, face-detection, dlib, face-average, facer, face-averaging",
"author": "John William Ruth Miller",
"author_email": "john.w.millr@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/3a/29/7ff5b79be49895cef3f44b7f81363db2cf18dabe83a53ef212b3594d03cb/average_facer-0.6.2.tar.gz",
"platform": null,
"description": "# Facer\n\nFace detection, alignment, and averaging using OpenCV and `dlib`.\n\nFacer 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.\n\n## Example\n\nThe 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/).\n\n[![Average faces of rap, rock, and country music](assets/average_face_example.png)](https://www.reddit.com/r/dataisbeautiful/comments/crxrud/the_average_faces_of_rap_rock_and_country/)\n\n## Installation\n\nYou 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.\n\n\nThe `requirements.txt` file lists the Python packages Facer depends on. Install the packages using `pip`:\n\n```bash\npip install -r requirements.txt\n```\n\n### Pre-trained detection model\n\nThe face landmark detection relies on a pre-trained model that must be downloaded separately from the `dlib` package itself.\n\n```shell\nwget http://dlib.net/files/shape_predictor_68_face_landmarks.dat.bz2\n```\n\nUnzip the compressed file after it finishes downloading and move it into the `./Facer/model` directory.\n\n## Usage\n\n```python\nfrom facer import facer\nimport matplotlib.pyplot as plt\n\n\n# Load face images\npath_to_images = \"./face_images\" # Put your images here\nimages = facer.load_images(path_to_images)\n\n# Detect landmarks for each face\nlandmarks, faces = facer.detect_face_landmarks(images)\n\n# Use the detected landmarks to create an average face\naverage_face = facer.create_average_face(faces, landmarks, save_image=True)\n\n# View the composite image\nplt.imshow(average_face)\nplt.show()\n```\n\nFacer also supports creating animated GIFs of the averaging process:\n\n```python\nfrom facer import facer\n\npath_to_images = \"./face_images\"\ngif, average_face = facer.create_animated_gif(path_to_images)\n```\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "Face averaging in Python made simple.",
"version": "0.6.2",
"project_urls": {
"Homepage": "https://github.com/johnwmillr/Facer",
"Repository": "https://github.com/johnwmillr/Facer"
},
"split_keywords": [
"opencv",
" image-processing",
" face-detection",
" dlib",
" face-average",
" facer",
" face-averaging"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "2c87850fa9b9fb27c599c8c466833c91bb6a022ba76a777cf2120741822a0c9f",
"md5": "1420b1a9e020ba87cbcec652f3034f58",
"sha256": "ccf0a0c2e2b85b7c732103c20f457f925574d52c52e34f580b18b6bf5db9f515"
},
"downloads": -1,
"filename": "average_facer-0.6.2-py3-none-any.whl",
"has_sig": false,
"md5_digest": "1420b1a9e020ba87cbcec652f3034f58",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": "<4.0,>=3.9",
"size": 9843,
"upload_time": "2024-11-15T06:29:46",
"upload_time_iso_8601": "2024-11-15T06:29:46.974320Z",
"url": "https://files.pythonhosted.org/packages/2c/87/850fa9b9fb27c599c8c466833c91bb6a022ba76a777cf2120741822a0c9f/average_facer-0.6.2-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "3a297ff5b79be49895cef3f44b7f81363db2cf18dabe83a53ef212b3594d03cb",
"md5": "9d8b61241593b793e303643ab4800650",
"sha256": "86da16b45e89b954350a77d9c895f5a746b84b71cf2ec8eff3099b985e36b7d0"
},
"downloads": -1,
"filename": "average_facer-0.6.2.tar.gz",
"has_sig": false,
"md5_digest": "9d8b61241593b793e303643ab4800650",
"packagetype": "sdist",
"python_version": "source",
"requires_python": "<4.0,>=3.9",
"size": 8884,
"upload_time": "2024-11-15T06:29:47",
"upload_time_iso_8601": "2024-11-15T06:29:47.876972Z",
"url": "https://files.pythonhosted.org/packages/3a/29/7ff5b79be49895cef3f44b7f81363db2cf18dabe83a53ef212b3594d03cb/average_facer-0.6.2.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-11-15 06:29:47",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "johnwmillr",
"github_project": "Facer",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"requirements": [],
"lcname": "average-facer"
}