/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

Current Crates.io Version

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 work is here (unmaintaned; since Aug 2021).

Building

Supported Platforms

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

For better maintenance, 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
  • Openblas (optional; overrides blas for better performance when enabling openblas feature )
  • dlib (optional; can be skipped by enabling build-native feature)
  • lapack

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

Installing Dependencies

ArchLinux
sudo pacman -S blas-openblas cmake

# optional[dlib]
paru -S dlib

Building Native library

dlib-face-recognition requires dlib to be installed. You can either provide a existing system-wide installation, or build it with this library.

  • To build it in compile-time:
    • cargo build --features build-native
  • To use a system-wide dependency:
    • cargo build

The C++ library dlib will be installed via dlib-face-recognition-sys when the build-native feature flag is enabled.

For the build, this library uses cmake , so please make sure to have cmake .

The build-native flag is disabled by default, offering increased build times.

Building Rust package

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

embed-all will enable the Default::default implementations the matching structs. These will search for the /files folder, and if a file doesn't exist it will be downloaded at runtime.

It is recommended to acquire the files before compile/runtime and set them in a protected location. The embed-all flag is disabled by default, offering increased build times.

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

For more information on examples: https://github.com/ulagbulag/dlib-face-recognition/tree/master/examples/README.md