FaceAiSharp 0.4.10

There is a newer version of this package available.
See the version list below for details.
dotnet add package FaceAiSharp --version 0.4.10                
NuGet\Install-Package FaceAiSharp -Version 0.4.10                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="FaceAiSharp" Version="0.4.10" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add FaceAiSharp --version 0.4.10                
#r "nuget: FaceAiSharp, 0.4.10"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install FaceAiSharp as a Cake Addin
#addin nuget:?package=FaceAiSharp&version=0.4.10

// Install FaceAiSharp as a Cake Tool
#tool nuget:?package=FaceAiSharp&version=0.4.10                

This package contains just FaceAiSharp's managed code and does not include any ONNX models. Take a look at FaceAiSharp.Bundle for a batteries-included package with everything you need to get started.

FaceAiSharp

FaceAiSharp is a .NET library that allows you to work with face-related computer vision tasks. It currently provides face detection, face recognition, facial landmarks detection, and eye state detection functionalities. FaceAiSharp leverages publicly available pretrained ONNX models to deliver accurate and efficient results and offers a convenient way to integrate them into your .NET applications. Whether you need to find faces, recognize individuals, detect facial landmarks, or determine eye states, FaceAiSharp simplifies the process with its simple API. ONNXRuntime is used for model inference, enabling hardware acceleration were possible.

Features

  • Face Detection: Identifies the boundaries of faces within images.
  • Face Recognition: Recognizes and distinguishes between different faces.
  • Facial Landmarks Detection: Detect and extract key facial landmarks such as eye centers, nose tip, and corners of the mouth.
  • Eye State Detection: Determine whether eyes are open or closed.

Key Highlights

  • Utilizes publicly available, state-of-the-art, pretrained ONNX models to ensure accuracy and performance.
  • All processing is done locally, with no reliance on cloud services.
  • Supports image-based face processing using ImageSharp.
  • Provides a simple and intuitive API for easy integration into your applications.
  • Cross-platform support for Windows, Linux, Android and more.

Getting Started

  1. Create a new console app dotnet new console

  2. Install two packages providing the relevant code and models:

    dotnet add package Microsoft.ML.OnnxRuntime
    dotnet add package FaceAiSharp.Bundle
    
  3. Replace the content of the Program.cs file with the following code:

    using FaceAiSharp;
    using FaceAiSharp.Extensions;
    using SixLabors.ImageSharp;
    using SixLabors.ImageSharp.PixelFormats;
    
    using var hc = new HttpClient();
    var groupPhoto = await hc.GetByteArrayAsync(
        "https://raw.githubusercontent.com/georg-jung/FaceAiSharp/master/examples/obama_family.jpg");
    var img = Image.Load<Rgb24>(groupPhoto);
    
    var det = FaceAiSharpBundleFactory.CreateFaceDetectorWithLandmarks();
    var rec = FaceAiSharpBundleFactory.CreateFaceEmbeddingsGenerator();
    
    var faces = det.DetectFaces(img);
    
    foreach (var face in faces)
    {
        Console.WriteLine($"Found a face with conficence {face.Confidence}: {face.Box}");
    }
    
    var first = faces.First();
    var second = faces.Skip(1).First();
    
    // AlignFaceUsingLandmarks is an in-place operation so we need to create a clone of img first
    var secondImg = img.Clone();
    rec.AlignFaceUsingLandmarks(img, first.Landmarks!);
    rec.AlignFaceUsingLandmarks(secondImg, second.Landmarks!);
    
    img.Save("aligned.jpg");
    Console.WriteLine($"Saved an aligned version of one of the faces found at \"./aligned.jpg\".");
    
    var embedding1 = rec.GenerateEmbedding(img);
    var embedding2 = rec.GenerateEmbedding(secondImg);
    
    var dot = embedding1.Dot(embedding2);
    
    Console.WriteLine($"Dot product: {dot}");
    if (dot >= 0.42)
    {
        Console.WriteLine("Assessment: Both pictures show the same person.");
    }
    else if (dot > 0.28 && dot < 0.42)
    {
        Console.WriteLine("Assessment: Hard to tell if the pictures show the same person.");
    }
    else if (dot <= 0.28)
    {
        Console.WriteLine("Assessment: These are two different people.");
    }
    
    
  4. Run the program you just created: dotnet run

See FaceAiSharp in Action

Try the interactive examples on https://facerec.gjung.com/ or review the code behind the app: https://github.com/georg-jung/explain-face-rec

Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on FaceAiSharp:

Package Downloads
FaceAiSharp.Bundle

FaceAiSharp allows you to work with face-related computer vision tasks easily. It currently provides face detection, face recognition, facial landmarks detection, and eye state detection functionalities. FaceAiSharp leverages publicly available pretrained ONNX models to deliver accurate and efficient results and offers a convenient way to integrate them into your .NET applications. Whether you need to find faces, recognize individuals, detect facial landmarks, or determine eye states, FaceAiSharp simplifies the process with its simple API. ONNXRuntime is used for model inference, enabling hardware acceleration were possible. All processing is done locally, with no reliance on cloud services. This is a bundle package that installs FaceAiSharp's managed code and multiple AI models in the ONNX format.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
0.5.23 245,659 2/18/2024
0.4.10 1,748 6/19/2023
0.3.7 199 6/15/2023
0.1.12 248 5/4/2023