Skip to content

torchbox/rustface-py

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

46 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Rustface-py

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.

Installation

Install with pip, wheel files are provided for Linux and macOS:

pip install wheel
pip install rustface

Pillow usage example

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)

Usage with Willow/Wagtail

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

Building from source

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

License

These bindings, Rustface and SeetaFace are all released under the BSD 2-Clause license.