baklava 0.1.5

A rust wrapper around the InsightFace library to perform face comparison
docs.rs failed to build baklava-0.1.5
Please check the build logs for more information.
See Builds for ideas on how to fix a failed build, or Metadata for how to configure docs.rs builds.
If you believe this is docs.rs' fault, open an issue.
Visit the last successful build: baklava-0.1.4

Baklava 🍮

A small project that wrap the InsightFace SDK in order to perform face comparison. It uses a fork of InsightFace in order to implement some convenient method to be exposed for Rust that can be found here. The implementation is based on the sample provided by the insightface team. c example link

Usage from crates.io

[!IMPORTANT] This guide required you to download the insightface library, to compile your own version and to follow the instructions in orders.

  1. To use the library you'll need to specify the model that will be used. These models are the same that are used by the InsightFace library. The models can be found here

  2. Clone the insightface's fork repository using this link and build the insightface library with the command

cd insightface/cpp-package/inspireface && git clone --recurse-submodules https://github.com/tunmx/inspireface-3rdparty.git 3rdparty
cd insightface/cpp-package/inspireface && bash command/build.sh
  1. Specify the path to the insightface library in your Cargo.toml by adding this into your .cargo/config.toml:
[env]
INSIGHTFACE_PATH = "<path to>/insightface/cpp-package/inspireface/build/inspireface-<arch>/InspireFace"

or you can set the INSIGHTFACE_PATH environment variable in your shell before building the project. Thereafter the library can be add as follows in your Cargo.toml and run the command cargo build to link the library:

[dependencies]
baklava = "0.1.5"

Below is a simple example of how to use the library:

// Should you have a list of images greater than 10. You can pass a chunk_size parameter in order to perform the image preparation concurrently.
let (cosine, percentage) = InsightFace::new("<model>", None)?
    .prepare_images(&[
        "./input1.png",
        "./input2.png",
    ])?
    .prepare_target_image("./target_image.png")?
    .compare_images(Methodology::Mean)?;

Running example

The example can be run by executing the following command:

cargo run --example compare

Recompile insightface

If you wish to recompile the InsightFace - rm -rf ./insightface/cpp-package/inspireface/build

Compile issues

Dynamic library not found

These includes error such as inspireface.h not found etc...

The linking between the InsightFace and Baklava is done through the build.rs script. It automatically build with the targeted architecture and copies the resulting dylib into the target directory. Should you encounter any issues try to pass the DYLIB_INCLUDE_PATH variable like below.

DYLD_LIBRARY_PATH=./insightface/cpp-package/inspireface/build/inspire-{arch}/InspireFace/lib cargo build

[!TIP]

If the inspireface.h could still not be found. Then you may try to build the InsightFace library by yourself. You can run the following command within the InsightFace directory.

cd insightface/cpp-package/inspireface
bash command/build/sh

This will build a dynamic library your current architecture within the build/inspire-{arch}/InspireFace/lib directory.