Face detection library for Python.
- Fast - Implemented in Rust, which is pretty fast
- Accurate - Implements a funnel-structured (FuSt) cascade schema for real-time multi-view face detection
- Easy to install - PEP 513 compliant, prebuilt wheel files provided for Linux and macOS. The entire algorithm is implemented inside this single <2MB package with no dependency on OpenCV or numpy
This module contains bindings to Rustface, a face detection library written in Rust which is derived from SeetaFace.
Install with pip, wheel files are provided for Linux and macOS:
pip install wheel
pip install rustface
from PIL import Image
from rustface import ImageData, Detector
image = Image.open('image.jpg')
imagedata = ImageData.from_pillow_image(image)
detector = Detector()
detector.set_min_face_size(20)
detector.set_score_thresh(2.0)
detector.set_pyramid_scale_factor(0.8)
detector.set_slide_window_step(4, 4)
for face in detector.detect(imagedata):
print(face.x, face.y, face.width, face.height)
This provides a Willow plugin that can be installed with the following code:
from willow.registry import registry
import rustface.willow
registry.register_plugin(rustface.willow)
(put this somewhere where it will run on startup)
To use this in Wagtail CMS, install the Willow plugin as per above and add the following into your project settings:
WAGTAILIMAGES_FEATURE_DETECTION_ENABLED = True
Install libffi, python3 headers, setuptools and wheel. The following command will install these on Ubuntu:
apt-get install libffi-dev python3-dev python3-setuptools python3-wheel
Check out the repository:
git clone git@github.com:torchbox/rustface-py.git
cd rustface-py
In order to compile the Rust code, you'll need to have Rust nightly toolchain installed and enabled.
Use rustup to set this up, find installation instructions for rustup at https://www.rustup.rs/
To use Rust nightly, run the following commands in the project root:
rustup update nightly
rustup override add nightly
Now you can build the package:
python3 setup.py bdist_wheel
These bindings, Rustface and SeetaFace are all released under the BSD 2-Clause license.