/dlib-face-recognition

Unofficial Rust wrappers to the C++ library dlib, face recognition tools

Primary LanguageRustBSD 3-Clause "New" or "Revised" LicenseBSD-3-Clause

dlib-face-recognition

Inspired by a similar python library, dlib-face-recognition is a Rust library that binds to certain specific features of the dlib C++ library.

This repository will dedicate itself to improve the library's content.

These include:

  • An FHOG-based face detector.
  • A CNN-based face detector (slower, but more powerful).
  • A face landmark predictor for identifying specific landmarks (eyes, nose, etc) from face rectangles.
  • A face encoding neural network for generating 128 dimensional face encodings that can be compared via their euclidean distances.

Original Working

The original working is here (unmaintaned; since Aug 2021).

Building

Supported Platforms

  • Linux { aarch64, x86_64 }
    • Ubuntu 20.04
  • MacOS { x86_64 }
    • Apple Silicon (Apple M1)
  • Windows { x86_64 }
    • Windows 10

For better maintaining, please let us know whether the other platforms support it. Besides, you may claim us whether the specific platform should support it through Issues .

Dependencies

  • cmake
  • blas
  • lapack

For Windows, vcpkg may help building both blas and lapack . For other platforms such as Linux, package managers should support installing them.

Building Native library

dlib-face-recognition requires dlib to be installed.

The C++ library dlib will be automatically installed via dlib-face-recognition-sys .

For building, this library uses cmake , so please make sure for getting cmake .

Building Rust package

dlib-face-recognition includes a embed-all feature flag that can be used with cargo build --features embed-all .

This will automatically download the face predictor, cnn face detector and face encoding neural network models (the fhog face detector is included in dlib and does not need to be downloaded). Alternatively, these models can be downloaded manually:

If this feature flag is enabled, the matching structs will have Default::default implementations provided that allows you to load them without having to worry about file locations.

# Install cmake on a CUDA-enabled machine ...
cargo build --features embed-all

Testing

There is one included test to recognize, and draw a face's points:

  • cargo run --features embed-all --example draw -> To run the example.

There is two files to benchmark the code, and test some functions:

  • cargo test --features embed-all --test benchmarks -> To run the benchmarks.
  • cargo test --features embed-all --test utilities_tests -> To run the utilities tester.

Examples

mkdir outputs
cargo run --features embed-all --example draw assets/obama_1.jpg outputs/obama_1.jpg