Warp, morph and average human faces!
Project description
Built with Python 2.7, OpenCV, Numpy, Scipy, Stasm.
Requirements
Install OpenCV: Mac installation steps
pip install -r requirements.txt
Either use as:
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>
Morph through a series of images in a folder:
python facemorpher/morpher.py --images=<folder>
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>]
[--alpha] [--plot]
Options:
-h, --help Show this screen.
--src=<src_imgpath> Filepath to source image (.jpg, .jpeg, .png)
--dest=<dest_path> 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
--alpha Flag to save transparent background [default: False]
--plot Flag to plot images [default: False]
--version Show version.
Averaging Faces
Average faces from all images in a folder:
python facemorpher/averager.py --images=<images_folder>
All options listed in averager.py (pasted below):
Face averager
Usage:
averager.py --images=<images_folder> [--blur] [--alpha] [--plot]
[--width=<width>] [--height=<height>] [--out=<filename>]
Options:
-h, --help Show this screen.
--images=<folder> Folder to images (.jpg, .jpeg, .png)
--blur Flag to blur edges of image [default: False]
--alpha Flag to save with transparent background [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]
--plot Flag to display the average face [default: False]
--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 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)
Details
Data for the haar face classifiers are in the facemorpher/data folder
Stasm binary in facemorpher/bin/stasm_util. You can build a new stasm binary with the Stasm 4 build scripts.
Documentation
http://alyssaq.github.io/face_morpher
Build & publish Docs
./scripts/publish_ghpages.sh
License
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
File details
Details for the file facemorpher-1.0.1.tar.gz.
File metadata
- Download URL: facemorpher-1.0.1.tar.gz
- Upload date:
- Size: 898.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
133ff457dca86b17362e60ea31fab946569f59f317a6d14a46101912c0369e17
|
|
| MD5 |
5b095fa4e4989306fc3c5662f84730e7
|
|
| BLAKE2b-256 |
cb3ca55769b2f68d703ca8b2fbf8896d9df4383753d54475ea39d8f06aa7f6d2
|