This is a python library that uses OpenCV to detect, align and extract faces images for classification purposes, either using HOG or Neural Network.
OpenCV is more than capable of doing everything that is needed in an image processing pipeline, such as: detect faces, align faces and extract faces, also known as Face Chips.
Clone the repository! If you have Anaconda just create an environment with the attached file:
conda env create -f newHogEnv.yml
To test just run the program pythonfaces.py:
python pythonfaces.py |image.jpg|
It has two other arguments:
python pythonfaces.py |image.jpg| |face cascade model| |eye cascade model|
If you enter only the image file name, it will assume the files that are in the "./data/haarcascades" folder.
The program detects the faces in the passed image, extracting each one in a new image. It transforms in monochrome, aligns the face (aligns the eyes horizontally) and cuts the person's face, in a square shape to the size you want.
There are several useful functions in this module and you can import it like this:
import pythonfaces
detectFaces
This function receives an OpenCV image (it can be a video frame), detects the faces in it and returns a list with images. The first is the original marked image (where the faces and eyes are) and the others are the cropped images of each face found (Face Chip), properly aligned and scaled.
You can save the images with:
cv2.imwrite(|path of the file to be written|, |OpenCV image object|)
The parameters are:
These models came from the original OpenCV project on Github.
See the code for pythonfaces.py for other functions.