Built with Python, OpenCV, Numpy, Scipy, Stasm.
Requirements
Install OpenCV: Mac installation steps
Note: OpenCV must be installed either from Homebrew or source as stasm requires the library files.
pip install -r requirements.txt
Either:
Use as local command-line utility
$ git clone https://github.com/alyssaq/face_morpher
Morphing Faces
Morph from a source to destination image:
python facemorpher/morpher.py --src=<src_imgpath> --dest=<dest_imgpath> --plot
Morph through a series of images in a folder:
python facemorpher/morpher.py --images=<folder> --out_video=out.avi
All options listed in morpher.py (pasted below):
Morph from source to destination face or
Morph through all images in a folder
Usage:
morpher.py (--src=<src_path> --dest=<dest_path> | --images=<folder>)
[--width=<width>] [--height=<height>]
[--num=<num_frames>] [--fps=<frames_per_second>]
[--out_frames=<folder>] [--out_video=<filename>]
[--plot] [--background=(black|transparent|average)]
Options:
-h, --help Show this screen.
--src=<src_imgpath> Filepath to source image (.jpg, .jpeg, .png)
--dest=<dest_imgpath> Filepath to destination image (.jpg, .jpeg, .png)
--images=<folder> Folderpath to images
--width=<width> Custom width of the images/video [default: 500]
--height=<height> Custom height of the images/video [default: 600]
--num=<num_frames> Number of morph frames [default: 20]
--fps=<fps> Number frames per second for the video [default: 10]
--out_frames=<folder> Folder path to save all image frames
--out_video=<filename> Filename to save a video
--plot Flag to plot images [default: False]
--background=<bg> Background of images to be one of (black|transparent|average) [default: black]
--version Show version.
Averaging Faces
Average faces from all images in a folder:
python facemorpher/averager.py --images=<images_folder> --out=average.png
All options listed in averager.py (pasted below):
Face averager
Usage:
averager.py --images=<images_folder> [--blur] [--plot]
[--background=(black|transparent|average)]
[--width=<width>] [--height=<height>]
[--out=<filename>] [--destimg=<filename>]
Options:
-h, --help Show this screen.
--images=<folder> Folder to images (.jpg, .jpeg, .png)
--blur Flag to blur edges of image [default: False]
--width=<width> Custom width of the images/video [default: 500]
--height=<height> Custom height of the images/video [default: 600]
--out=<filename> Filename to save the average face [default: result.png]
--destimg=<filename> Destination face image to overlay average face
--plot Flag to display the average face [default: False]
--background=<bg> Background of image to be one of (black|transparent|average) [default: black]
--version Show version.
Steps (facemorpher folder)
1. Locator
Locates face points (using stasm)
For a different locator, return an array of (x, y) control face points
2. Aligner
Align faces by resizing, centering and cropping to given size
3. Warper
Given 2 images and its face points, warp one image to the other
Triangulates face points
Affine transforms each triangle with bilinear interpolation
4a. Morpher
Morph between 2 or more images
4b. Averager
Average faces from 2 or more images
Blender
Optional blending of warped image:
Weighted average
Alpha feathering
Poisson blend
Examples - Being John Malkovich
Create a morphing video between the 2 images:
(out.avi played and recorded as gif)
Save the frames to a folder:
Plot the frames:
Average all face images in a folder:
85 images used
Use as pip library
$ pip install facemorpher
Examples
Additional options are exactly the same as the command line
import facemorpher
# Get a list of image paths in a folder
imgpaths = facemorpher.list_imgpaths('imagefolder')
# To morph, supply an array of face images:
facemorpher.morpher(imgpaths, plot=True)
# To average, supply an array of face images:
facemorpher.averager(['image1.png', 'image2.png'], plot=True)
Once pip installed, 2 binaries are also available as a command line utility:
$ facemorpher --src=<src_imgpath> --dest=<dest_imgpath> --plot $ faceaverager --images=<images_folder> --plot
Try out in a docker container
Mount local folder to /images in docker container, run it and enter a bash session. –rm removes the container when you close it.
$ docker run -v /Users/alyssa/Desktop/images:/images --name py3 --rm -it jjanzic/docker-python3-opencv bash
Once you’re in the container, install facemorpher and try the examples listed above
root@0dad0912ebbe:/# pip install facemorpher root@0dad0912ebbe:/# facemorpher --src=<img1> --dest=<img2> --plot
Details
Face points are detected with stasm. This library relies on the python wrapper around stasm.
Documentation
http://alyssaq.github.io/face_morpher
Build & publish Docs
./scripts/publish_ghpages.sh
License
Metadata
Release files for facemorpher 5.2.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| facemorpher-5.2.1.tar.gz | 13.1 kB | Details |
Built distributions (wheels)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| facemorpher-5.2.1-py3-none-any.whl | Python 3 | none | any | Details |
| facemorpher-5.2.1-py2-none-any.whl | Python 2 | none | any | Details |
Total release size: 51.6 kB
Release files / facemorpher-5.2.1.tar.gz
| Download URL | facemorpher-5.2.1.tar.gz |
|---|---|
| Size | 13.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
5dadb7b62e34d9ba63bfd4c75b59dbd1139caa80b28512212393efdd41b93374
|
|
BLAKE2b-256 checksum How to use checksums |
c8ba43c1832eea880d396d69fda96cde225e2dc2caa4d9382309d367bd6f1873
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.12.1 pkginfo/1.4.2 requests/2.21.0 setuptools/40.6.3 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.7.2
|
Release files / facemorpher-5.2.1-py3-none-any.whl
| Download URL | facemorpher-5.2.1-py3-none-any.whl |
|---|---|
| Size | 17.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
a81568cce4f2b8cfe41bfa71e5de3aa32ad66d2de5f900e3d8c3812d159a61c1
|
|
BLAKE2b-256 checksum How to use checksums |
6b4db0d03069d58a71da2b94db1ac8f1326dfffa55899bc0d202e9fd6d95e59c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.12.1 pkginfo/1.4.2 requests/2.21.0 setuptools/40.6.3 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.7.2
|
Release files / facemorpher-5.2.1-py2-none-any.whl
| Download URL | facemorpher-5.2.1-py2-none-any.whl |
|---|---|
| Size | 20.9 kB |
| Tags | Python 2 |
|
SHA-256 checksum How to use checksums |
e1406e1701b8d21e5c3ddc46f7466bd5bfcb53fd0be8717e6b9b45c70841485b
|
|
BLAKE2b-256 checksum How to use checksums |
07bf3b7760d19566624e1f831e9aff26228cd5c8447b1aa1189866980a27ccf5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.12.1 pkginfo/1.4.2 requests/2.21.0 setuptools/40.6.3 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.7.2
|