Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 31 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,37 +1,45 @@
FaceAlign
========

FaceAlign is a tool that can be used to align a set of images containing faces. It is particularly useful for creating "time-lapse" face videos, such as this one : http://youtube.com/watch?v=7SXErQ4eYGU
====
FaceAlign is a tool that can be used to align a set of images containing faces.
It is particularly useful for creating time-lapse face videos, such as [this one](http://youtube.com/watch?v=7SXErQ4eYGU).

How it works
------------
----
FaceAlign is a Python script that uses [OpenCV python bindings](http://OpenCV.willowgarage.com/wiki/) (which requires >= Python 2.6).
It detects the location of the face in each image (OpenCV tends to err on the side of over-detection, and this tool will use the largest detected face) and will scale and offset the image so that the centers of the faces in all images match up.
This is based on parameters that can be easily set in [config.py](src/config.py).

FaceAlign is a Python script that uses [opencv python bindings](http://opencv.willowgarage.com/wiki/), which requires >= Python 2.6. It detects the location of the face in each image (opencv tends to err on the side of over-detection, and this tool will use the largest detected face) and will scale and offset the image so that the centers of the faces in all images will match up. This is based on parameters that can be easily set in config.py.
On OS X, OpenCV can be installed with [homebrew](http://brew.sh).
To do so, install homebrew and run the following command in your terminal.

$ brew install OpenCV --32-bit

Usage
-----
----
Once Python and [OpenCV](http://OpenCV.org) are installed, open [config.py](src/config.py) and set HCDIR to the folder containing your OpenCV installation's Haar cascade files.

Once python and opencv are installed, open config.py and set HCDIR to the folder containing your opencv installation's Haar cascade files.
On OS X, you can find the Haar cascade files under `/usr/local/Cellar/OpenCV/2.4.9/share/OpenCV/haarcascades` if you've used homebrew to install OpenCV.

Run sizeToFace.py. It takes a required input directory parameter, and an optional output directory parameter. The output directory will be created if it does not already exist. By default, images will be output to the current directory. Output file names will be numbered starting with 0001.jpg.
Run sizeToFace.py.
It takes a required input directory parameter, and an optional output directory parameter.
The output directory will be created if it does not already exist.
By default, images will be output to the current directory.
Output file names will be numbered starting with 0001.jpg.

$ python src/sizeToFace.py ../in-images

$ python src/sizeToFace.py ../in-images ../out-images

Eventual plans
--------------

----
* Brightness/contrast normalization
* Integration with ffmpeg for automatic video generation
* A GUI

Common Errors/Solutions
-----------------------
----
ImportError: No module named cv

**Solution**: You have not installed OpenCV or the OpenCV Python bindings

**Solution**: You have not installed OpenCV or the OpenCV Python bindings.

Traceback (most recent call last):
File "<...>/src/facealign/src/FaceImage.py", line 133, in runFaceImage
Expand All @@ -42,11 +50,14 @@ Common Errors/Solutions
cascade = cv.Load(HCPATH)
TypeError: OpenCV returned NULL

**Solution**: This means you have not set your HCDIR variable correctly. Open src/config.py and set HCDIR to
[yourOpenCVDir]/opencv/data/haarcascades/, for example:
HCDIR = '/home/doriad/src/OpenCV/opencv/data/haarcascades/'
**Solution**: This means you have not set your HCDIR variable correctly.
*Open src/config.py and set HCDIR to
[yourOpenCVDir]/OpenCV/data/haarcascades/, for example:
HCDIR = '/home/doriad/src/OpenCV/OpenCV/data/haarcascades/'

So what's up?
-------------

Feedback, ideas, issue reports, and contributions are invited. Welcomed. Demanded, even. FaceAlign is fairly simple at the moment but I would be interested to hear if you found it useful.
----
Feedback, ideas, issue reports, and contributions are invited.
Welcomed.
Demanded, even.
FaceAlign is fairly simple at the moment but I would be interested to hear if you found it useful.
20 changes: 9 additions & 11 deletions src/config.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#: The path to the opencv install's Haar cascade folder
HCDIR = 'C:/opencv/sources/data/haarcascades/'
HCDIR = '/usr/local/Cellar/opencv/2.4.9/share/OpenCV/haarcascades'

#: The name of the eyepair Haar cascade file to use
HC_EYEPAIR_NAME = 'haarcascade_mcs_eyepair_big.xml'
Expand All @@ -14,20 +14,19 @@
HC_FACE_NAME = 'haarcascade_frontalface_alt2.xml'

#: The final image height
HEIGHT_TARGET = 720
HEIGHT_TARGET = 1088

#: The final image width
WIDTH_TARGET = 960
WIDTH_TARGET = 816

#: What is used when the image must be offset too far? 0 for black border, 1 for stretch colors
GAP_BORDER = 1

GAP_BORDER = 0


# Debugging parameters

#: If True, print debug info
DEBUG = True
DEBUG = False

#: If true, will mark on the image the eyes/eyepairs which were selected to be used for calculations
MARKUSED = False
Expand All @@ -39,8 +38,7 @@
NOTRANSFORM = False

#: If true, skip individual eye/eyepair detection, and go to face detection
FORCE_FULL_FACE = True

FORCE_FULL_FACE = False


# Face characteristics, may need to be tweaked per face
Expand All @@ -65,10 +63,10 @@
FACE_WIDTH_TO_EYE_WIDTH = .41

#: The minimum size detection threshold for eyepair as a fraction of the image size
EYEPAIR_MIN_SIZE = (.15, .03)
EYEPAIR_MIN_SIZE = (.05, .03)

#: The maximum size detection threshold for eyepair as a fraction of the image size
EYEPAIR_MAX_SIZE = (.55, 1)
EYEPAIR_MAX_SIZE = (.65, 1)



Expand Down Expand Up @@ -108,4 +106,4 @@
MID_Y_TARGET = HEIGHT_TARGET*MID_Y_TARGET_RATIO

#: Reject a left/right pair of eyes if one is larger by this factor or more
EYE_MAX_SIZE_DIFFERENCE = 2
EYE_MAX_SIZE_DIFFERENCE = 2