Giter VIP home page Giter VIP logo

takuya-takeuchi / facerecognitiondotnet Goto Github PK

View Code? Open in Web Editor NEW
1.1K 56.0 263.0 27.72 MB

The world's simplest facial recognition api for .NET on Windows, MacOS and Linux

License: MIT License

C# 73.55% Batchfile 0.76% Shell 0.49% PowerShell 17.30% Dockerfile 0.49% CMake 2.45% C++ 1.98% Python 1.81% C 0.62% Makefile 0.58%
face-recognition machine-learning face-detection dotnet windows linux macos age-classification gender-classification headpose-estimation

facerecognitiondotnet's Introduction

FaceRecognitionDotNet

The world's simplest facial recognition api for .NET
This repository is porting https://github.com/ageitgey/face_recognition by C#.

This package supports cross platform, Windows, Linux and MacOSX!!

Package OS x86 x64 ARM ARM64 Nuget
FaceRecognitionDotNet (CPU) Windows - - - NuGet version
Linux - - - NuGet version
OSX - - - NuGet version
FaceRecognitionDotNet for CUDA 9.2 Windows - - - NuGet version
Linux - - - NuGet version
OSX - - - - NuGet version
FaceRecognitionDotNet for CUDA 10.0 Windows - - - NuGet version
Linux - - - NuGet version
OSX - - - - NuGet version
FaceRecognitionDotNet for CUDA 10.1 Windows - - - NuGet version
Linux - - - NuGet version
OSX - - - - NuGet version
FaceRecognitionDotNet for CUDA 10.2 Windows - - - NuGet version
Linux - - - NuGet version
OSX - - - - NuGet version
FaceRecognitionDotNet for CUDA 11.0 Windows - - - NuGet version
Linux - - - NuGet version
OSX - - - - NuGet version
FaceRecognitionDotNet for CUDA 11.1 Windows - - - NuGet version
Linux - - - NuGet version
OSX - - - - NuGet version
FaceRecognitionDotNet for CUDA 11.2 Windows - - - NuGet version
Linux - - - NuGet version
OSX - - - - NuGet version
FaceRecognitionDotNet for Intel MKL Windows - - - NuGet version
Linux - - - NuGet version
OSX - - - NuGet version
FaceRecognitionDotNet for ARM Windows - - - - NuGet version
Linux - - - - NuGet version
OSX - - - - NuGet version
⚠️ FaceRecognitionDotNet for ARM is not tested yet

Support API

face_recognition API Corresponding API Note
batch_face_locations BatchFaceLocations
compare_faces CompareFaces
face_distance FaceDistance
face_encodings FaceEncodings
face_landmarks FaceLandmarks And support Helen dataset ⚠️
face_locations FaceLocations And support to get confidence and use custom face detector
load_image_file LoadImageFile
- CropFaces Crop image with specified locations
- EyeBlinkDetect Detect person is blinking or not
Support Large model and Helen dataset ⚠️
- LoadImage From memory data or System.Drawing.Bitmap
- PredictAge Predict human age.
Use Adience Benchmark Of Unfiltered Faces For Gender And Age Classification dataset ⚠️
- PredictEmotion Predict emotion for human face.
Use Corrective re-annotation of FER - CK+ - KDEF ⚠️
- PredictGender Predict human gender.
Use UTKFace dataset ⚠️
- PredictProbabilityAge Predict probability of human age.
Use Adience Benchmark Of Unfiltered Faces For Gender And Age Classification dataset ⚠️
- PredictProbabilityEmotion Predict probability of emotion from human face.
Use Corrective re-annotation of FER - CK+ - KDEF ⚠️
- PredictProbabilityGender Predict probability of human gender.
Use UTKFace dataset ⚠️
- PredictHeadPose Predict human head pose.
Use 300W-LP dataset ⚠️
⚠️ Warning

You must train dataset by yourself. I will NOT provide pretrained model file due to avoiding license issue. You can check the following examples to train dataset.

  • tools/AgeTraining
  • tools/EmotionTraining
  • tools/EmotionTrainingV2
  • tools/GenderTraining
  • tools/HeadPoseTraining
  • tools/HelenTraining

Demo

Face Recognition

Other Face Functions

Face Landmark Age and Gender Classification Head Pose Estimation Emotion Estimation

Document

FaceRecognitionDotNet support full xml document for Visual Studio. A xml document is written English and Japanese. And you can check online document at FaceRecognitionDotNet API Document

Dependencies Libraries and Products

License: The MIT License

Author: Adam Geitgey

Principal Use: The world's simplest facial recognition api for Python and the command line. Main goal of FaceRecognitionDotNet is what ports face_recognition by C#.

License: Creative Commons Zero v1.0 Universal License

Author: Adam Geitgey

Principal Use: Trained models for the face_recognition python library

License: Boost Software License

Author: Davis E. King

Principal Use: A toolkit for making real world machine learning and data analysis applications in C++.

License: The MIT License

Author: Takuya Takeuchi

Principal Use: Use dlib interface via .NET. This library is developed by this owner.

License: The BSD 3-Clause License

Author: shimat

Principal Use: Loading image data by opencv wrapper for example

facerecognitiondotnet's People

Contributors

takuya-takeuchi avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

facerecognitiondotnet's Issues

Referencing nuget package breaks `dotnet publish`

Hey @takuya-takeuchi

Unfortunately after moving from self-compiled to using a nuget package the dotnet publish command seems to be broken:

Step 6/111 : RUN dotnet publish src/${project}/${project}.csproj -c Release -o /app/out/ --no-restore --no-build
 ---> Running in dd8dc333ad2e
Microsoft (R) Build Engine version 16.0.450+ga8dc7f1d34 for .NET Core
Copyright (C) Microsoft Corporation. All rights reserved.

/usr/share/dotnet/sdk/2.2.202/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Publish.targets(169,5): error MSB3030: Could not copy the file "obj/x64/Release/netcoreapp2.2/People.Service.pdb" because it was not found. [/app/src/People.Service/People.Service.csproj]
/usr/share/dotnet/sdk/2.2.202/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Publish.targets(169,5): error MSB3030: Could not copy the file "obj/x64/Release/netcoreapp2.2/People.Service.dll" because it was not found. [/app/src/People.Service/People.Service.csproj]
/usr/share/dotnet/sdk/2.2.202/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Publish.targets(169,5): error MSB3030: Could not copy the file "/app/src/People.Common/bin/x64/Release/netcoreapp2.2/People.Common.dll" because it was not found. [/app/src/People.Service/People.Service.csproj]
/usr/share/dotnet/sdk/2.2.202/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Publish.targets(169,5): error MSB3030: Could not copy the file "/app/src/People.Service.Hub/bin/x64/Release/netcoreapp2.2/People.Service.Hub.dll" because it was not found. [/app/src/People.Service/People.Service.csproj]
The command '/bin/sh -c dotnet publish src/${project}/${project}.csproj -c Release -o /app/out/ --no-restore --no-build' returned a non-zero code: 1

I'm using AnyCPU so for all my projects and suddenly after referencing the DlibDotNet the publisher is looking for an x64 compilation folder. Switching from AnyCPU to x64 in the .csproj file doesn't help.

Any ideas?

FaceRecognition.LoadImage usage.

I use Aforge to capture camera frame.
On NewFrame arrive, I invoke FaceRecognition.LoadImage to prepare EncodingFace, but I don't know how to convert System.Drawing.Bitmap to byte array and get row,s cols.

FaceEncodings too slow

hi @takuya-takeuchi
frist thanks for your work.
i get img from web camera and FaceEncoding it but too slow.
i save one img and use this code to test
it will take about 5000ms to FaceEncoding.
is the img size too big or what ?
(win10 64 i7 6700)
Stopwatch getTime = new Stopwatch(); Image im = FaceRecognition.LoadImageFile("1,jpg"); getTime.Start(); FaceEncoding[] array2 = fr.FaceEncodings(im).ToArray<FaceEncoding>(); getTime.Stop(); textBox2.Text = getTime.ElapsedMilliseconds + "\r\n";

1

AccessViolationException

My english is bad!
When I use the lib,I often get Exception at these two places:
recognition.FaceLocations(image).ToArray()
recognition.FaceEncodings(image).ToArray()
the Exception is :
System.AccessViolationException: Attempted to read or write protected memory This is often an indication that other memory is corrupt

at DlibDotNet.NativeMethods.frontal_face_detector_matrix_operator2(IntPtr detector, MatrixElementType imgType, IntPtr img, Double adjustThreshold, IntPtr dets)
at DlibDotNet.FrontalFaceDetector.Operator(MatrixBase image, IEnumerable1& detections, Double threshold) at FaceRecognitionDotNet.Dlib.Python.SimpleObjectDetector.RunDetectorWithUpscale1(FrontalFaceDetector detector, Image img, UInt32 upsamplingAmount, Double adjustThreshold, List1 detectionConfidences, List1 weightIndices) at FaceRecognitionDotNet.Dlib.Python.SimpleObjectDetector.RunDetectorWithUpscale2(FrontalFaceDetector detector, Image image, UInt32 upsamplingAmount) at FaceRecognitionDotNet.FaceRecognition.RawFaceLocations(Image faceImage, Int32 numberOfTimesToUpsample, Model model) at FaceRecognitionDotNet.FaceRecognition.<FaceLocations>d__18.MoveNext() at System.Linq.Buffer1..ctor(IEnumerable1 source) at System.Linq.Enumerable.ToArray[TSource](IEnumerable1 source)

My c# code is like this:
lock (locker)
{
Bitmap bitmap = (Bitmap)bmp.Clone();
var array2d = bitmap.ToArray2D();
var image = FaceRecognition.LoadImage(array2d.ToBytes(), array2d.Rows, array2d.Columns, 3);
Location[] locations = recognition.FaceLocations(image).ToArray();
return locations;
}

I don't know how it happens?
Any one if know how to solve it,thank you,please help me!

Running .FaceEncodings(image) possible in parallel?

I'm trying to run the code in parallel on multiple CPU cores, just like the example (https://github.com/takuya-takeuchi/FaceRecognitionDotNet/tree/master/examples/FaceDetection). But the distances that I print out with the following code (see down below) are not between 0 and 2 and actually do not make any sense.

Do I miss a thing or is the Encoding calculation just not possible to run in Paralell?

I am using the cpu nuget package in a .Net Core console app.

class Program
{
    public static FaceRecognition faceRecognition { get; set; }
    public static List<FaceEncoding> Results { get; set; }

    static void Main(string[] args)
    {
        faceRecognition = FaceRecognition.Create("models");
        
        DirectoryInfo d = new DirectoryInfo(Path.GetFullPath("images/test"));
        List<FileInfo> files = d.GetFiles().ToList();
        var testEncoding = calcEncoding(files[0]);

        Results = new List<FaceEncoding>();
        Object Lock = new Object();

        var option = new ParallelOptions
        {
            MaxDegreeOfParallelism = Environment.ProcessorCount
        };

        DateTime time = DateTime.Now;
        Parallel.For(1, files.Count, option, i=>
        {
            calcEncodings(files[i], Lock);
        });
        double totalTime = (DateTime.Now - time).TotalSeconds;
        Console.WriteLine($"Time: {totalTime}, images/s: {files.Count/totalTime}");

        Results.ForEach(r =>
        {
            Console.WriteLine(FaceRecognition.FaceDistance(r, testEncoding));
        });

        Console.ReadLine();
    }

    private static void calcEncodings(FileInfo file, Object Lock)
    {
        using(var image = FaceRecognition.LoadImageFile(file.FullName))
        {
            var faceEncodings = faceRecognition.FaceEncodings(image);

            foreach(var faceEncoding in faceEncodings)
            {
                Console.WriteLine($"{file.Name}: {faceEncoding.Size}");
                lock (Lock)
                {
                    Results.Add(faceEncoding); 
                }
            }
        }
    }

    private static FaceEncoding calcEncoding(FileInfo file)
    {
        using (var image = FaceRecognition.LoadImageFile(file.FullName))
        {
            return faceRecognition.FaceEncodings(image).First() ;               
        }
    }
}

Result:

77330,4555392426
116594805,513795
3905512926785,24
99675592693821,5
9,99817851362896E+15
8,02151826515965E+17
8,16535264000558E+18
7,76799579452464E+18
NaN
NaN
NaN
NaN
NaN
NaN
NaN
NaN
2442073,74932843
7821815,3598267
106,853336907902
106,854189097259

Upsampling causing CudaException code 2

The following breaks with CUDA:

_faceRecognition.FaceLocations(image, 1, _model).ToList();

The following works w/wo CUDA:

_faceRecognition.FaceLocations(image, 0, _model).ToList();

In python I do 1 upsample and it works fine.

Looks like a memory leak?

cc @takuya-takeuchi

KNN comparer

@takuya-takeuchi I see that you are comparing with O(N^2) complexity, which is fine for 1-2 known people, but when you run into 1000s of known identities that will be way too slow. In python face_recognition it is recommended to use KNN classifier in order to find the best match. It's got way better performance for bigger datasets.

NumJitters causing problems

I get VERY different results between:

_faceRecognition.FaceEncodings(image, locations, 1);

and

_faceRecognition.FaceEncodings(image, locations, 100);

The first one gives values like 0.5324223232 but the other one gives values 3.954389834-E15, which is basically a 0.

Unable to load image

var unknownImage = FaceRecognition.LoadImageFile("D:\\Bibliothek\\Bilder\\IMG_3385.jpg");

System.BadImageFormatException
HResult=0x8007000B
Message=Es wurde versucht, eine Datei mit einem falschen Format zu laden. (Ausnahme von HRESULT: 0x8007000B)
Source=DlibDotNet
StackTrace:
at DlibDotNet.Dlib.Native.load_image_matrix(MatrixElementType type, Byte[] path, IntPtr& matrix)
at DlibDotNet.Dlib.LoadImageAsMatrix[T](String path)
at FaceRecognitionDotNet.FaceRecognition.LoadImageFile(String file, Mode mode)
at ConsoleApp1.Program.Main(String[] args) in C:\Users\Sven Trittler\Desktop\ConsoleApp1\ConsoleApp1\Program.cs:line 197

Potential bug - DlibDotNet

Hi there!

Inside the DlibDotNet folder -> Matrix -> Matrix.cs it seems to be a mistake, or I might not understand the purpose with this line of code.

At line 197 there is an if statement inside the function public Matrix(byte[] array, int row, int column, int elementSize)

if(column <1) do throw new arg (ElementSize) "should be more than 1".

Shouldn't it instead be if(elementSize < 1) do throw new arg (ElementSize) "should be more than 1".

If this isn't a bug, could u explain why this is a "Throw new exception" because the line over is stating a similar statement "if(column < 0)"

Kind regards Lucas

CudaException code 77

I'm getting the following error:

      CUDA Error Lib:libDlibDotNet.Native.Dnn.so Code:77 Driver:10000 Runti,:10000 Message:Exception of type 'DlibDotNet.CudaException' was thrown..
fail: People.Service[0]
      Exception of type 'DlibDotNet.CudaException' was thrown.
DlibDotNet.CudaException: Exception of type 'DlibDotNet.CudaException' was thrown.
   at DlibDotNet.Dnn.Cuda.ThrowCudaException(ErrorType error)
   at DlibDotNet.Dnn.LossMmod.Operator[T](IEnumerable`1 images, UInt64 batchSize)
   at FaceRecognitionDotNet.Dlib.Python.CnnFaceDetectionModelV1.Detect(LossMmod net, Image image, Int32 upsampleNumTimes)
   at FaceRecognitionDotNet.FaceRecognition.RawFaceLocations(Image faceImage, Int32 numberOfTimesToUpsample, Model model)
   at FaceRecognitionDotNet.FaceRecognition.FaceLocations(Image image, Int32 numberOfTimesToUpsample, Model model)+MoveNext()
   at System.Collections.Generic.List`1.AddEnumerable(IEnumerable`1 enumerable)
   at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
   at People.Common.Services.IdentificationService.IdentifyAsync(Guid applicationId, Mat frame, Double tolerance) in /app/src/People.Common/Services/IdentificationService.cs:line 70
   at People.Common.Pipeline.Blocks.IdentificationBlock.CheckIdentityAsync(Result result) in /app/src/People.Common/Pipeline/Blocks/IdentificationBlock.cs:line 54

Any ideas what this means? Googling the error code

CudaException 77

Hey @takuya-takeuchi

Unfortunately error still exists. It happens when multiple threads try to do face recognition at the same time.

Stack trace:

info: People.Service[0]
      CUDA Error Lib:libDlibDotNet.Native.Dnn.so Code:77 D:10000 R:10000 M:Exception of type 'DlibDotNet.CudaException' was thrown..
fail: People.Service[0]
      Exception of type 'DlibDotNet.CudaException' was thrown.
DlibDotNet.CudaException: Exception of type 'DlibDotNet.CudaException' was thrown.
   at DlibDotNet.Dnn.Cuda.ThrowCudaException(ErrorType error)
   at DlibDotNet.Dnn.LossMmod.Operator[T](IEnumerable`1 images, UInt64 batchSize)
   at FaceRecognitionDotNet.Dlib.Python.CnnFaceDetectionModelV1.Detect(LossMmod net, Image image, Int32 upsampleNumTimes)
   at FaceRecognitionDotNet.FaceRecognition.RawFaceLocations(Image faceImage, Int32 numberOfTimesToUpsample, Model model)
   at FaceRecognitionDotNet.FaceRecognition.FaceLocations(Image image, Int32 numberOfTimesToUpsample, Model model)+MoveNext()
   at System.Collections.Generic.List`1.AddEnumerable(IEnumerable`1 enumerable)
   at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)

Random crashes in Unity

Hi @takuya-takeuchi, I've imported and used the library in an Unity project, however about half the times the library throws a runtime error: "This application has requested the runtime to terminate it in an unusual way. Please contact the application's support team for more information", in the cases when it doesn't crash, it works perfectly and gives output. I've tested this using faceEncodingPerformance code as well with same results.

I've used version 1.2.3.4 of FaceRecognitionDotNet and dependency on DlibDotNet version 19.15.0.20180916

FaceRecognition.FaceEncodings() Too slow

I create a wpf demo for face compare, the code is as following:

        private void StartVideo()
        {
            tVideo = new Thread(new ThreadStart(() =>
            {
                using (var cap = new VideoCapture(0))
                {
                    if (!cap.IsOpened())
                        return;

                    OpenCvSharp.Point pLeftTop = new OpenCvSharp.Point();
                    OpenCvSharp.Point pRightBottom = new OpenCvSharp.Point();
                    int roiWidth = 260;
                    int roiHeight = 360;

                    Mat target = Cv2.ImRead("yuzifu.jpg");
                    var arrtarget = new byte[target.Width * target.Height * target.ElemSize()];
                    Marshal.Copy(target.Data, arrtarget, 0, arrtarget.Length);
                    var temptarget = Dlib.LoadImageData<RgbPixel>(arrtarget, (uint)target.Height, (uint)target.Width, (uint)(target.Width * target.ElemSize()));
                    var imgtarget = FaceRecognition.LoadImageData(temptarget);
                    var endodings = this._FaceRecognition.FaceEncodings(imgtarget).ToArray();

                    cap.FrameWidth = 800;
                    cap.FrameHeight = 600;
                    cap.FourCC = "MJPG";
                    using (Mat srcImg = new Mat())
                    {
                        while (running)
                        {
                            cap.Read(srcImg);
                            if (srcImg.Width > 0 && srcImg.Height > 0)
                            {
                                Cv2.Flip(srcImg, srcImg, FlipMode.Y);

                                pLeftTop.X = (srcImg.Width - roiWidth) / 2;
                                pLeftTop.Y = (srcImg.Height - roiHeight) / 2;
                                pRightBottom.X = pLeftTop.X + roiWidth;
                                pRightBottom.Y = pLeftTop.Y + roiHeight;
                                OpenCvSharp.Rect roi = new OpenCvSharp.Rect(pLeftTop.X, pLeftTop.Y, roiWidth, roiHeight);
                                Mat imageROI = srcImg.Clone(roi);

                                bool result = CompareFace(imageROI, endodings);

                                srcImg.Rectangle(pLeftTop, pRightBottom, Scalar.FromRgb(0, 255, 150));
                                Dispatcher.Invoke(()=>
                                {
                                    if (!srcImg.IsDisposed)
                                        FrontVideo.Source = srcImg.ToBitmapSource();
                                    Name.Text = result ? "Yuzifu" : "Unknow";
                                });
                            }
                        }
                    }
                }
            }));
            tVideo.Start();
        }

        private bool CompareFace(Mat source, FaceEncoding[] endtarget)
        {
            bool rtn = false;
            var arrsource = new byte[source.Width * source.Height * source.ElemSize()];
            Marshal.Copy(source.Data, arrsource, 0, arrsource.Length);
            var tempsource = Dlib.LoadImageData<RgbPixel>(arrsource, (uint)source.Height, (uint)source.Width, (uint)(source.Width * source.ElemSize()));

            using (var imgsource = FaceRecognition.LoadImageData(tempsource))
            {
                var locals = this._FaceRecognition.FaceLocations(imgsource);

                // too slow
                var endodings1 = this._FaceRecognition.FaceEncodings(imgsource, locals).ToArray();

                foreach (var encoding in endodings1)
                    foreach (var compareFace in FaceRecognition.CompareFaces(endtarget, encoding))
                    {
                        if (compareFace)
                        {
                            rtn = true;
                            break;
                        }
                    }

                foreach (var encoding in endodings1)
                    encoding.Dispose();
            }

            return rtn;
        }

        // Add func to FaceRecognition
        public static Image LoadImageData(Array2D<RgbPixel> array)
        {
            return new Image(new Matrix<RgbPixel>(array));
        }

By tracking the running time, execute FaceEncodings() need a lot of time, at least 600 milliseconds, many times more than 1 second.

FaceLandmark not static

I'm using FaceRecognition thorugh the static method calls. My images are not on disk therefore using the Create method does not work for me.

Please makeFaceLandmark method static.

cc @takuya-takeuchi

nuget package is missing native dlls?

Hello @takuya-takeuchi,

thank you so much on your work on wrapping dlib.
It's amazing.

I've just noticed, that the nuget package for the FaceRecognitionDotNet doesn't include native

  • DlibDotNetNative.dll
  • DlibDotNetNativeDnn.dll

The DlibDotNet has these packages.

Am I doing something wrong? My machine complains, that it can't find these two dlls.
What will be a workaround if you didn't include these native dlls intentionally?

Best,
Anton

Code find a error

Source Python code here is :

def _raw_face_locations(img, number_of_times_to_upsample=1, model="hog"):
    """
    Returns an array of bounding boxes of human faces in a image

    :param img: An image (as a numpy array)
    :param number_of_times_to_upsample: How many times to upsample the image looking for faces. Higher numbers find smaller faces.
    :param model: Which face detection model to use. "hog" is less accurate but faster on CPUs. "cnn" is a more accurate
                  deep-learning model which is GPU/CUDA accelerated (if available). The default is "hog".
    :return: A list of dlib 'rect' objects of found face locations
    """
    if model == "cnn":
        return cnn_face_detector(img, number_of_times_to_upsample)
    else:
        return face_detector(img, number_of_times_to_upsample)

But Code Here is :

  private IEnumerable<MModRect> RawFaceLocations(Image faceImage, int numberOfTimesToUpsample = 1, Models model = Models.Hog)
        {
            switch (model)
            {
                case Models.Hog:
                    return CnnFaceDetectionodelV1.Detect(this._CnnFaceDetector, faceImage.Matrix, numberOfTimesToUpsample);
                default:
                    return this._FaceDetector.Operator(faceImage.Matrix, numberOfTimesToUpsample).Select(rectangle => new MModRect() { Rect = rectangle });
            }
        }

At FaceRecognition.cs File

Can you fix this ? Thank you ~

You should 'case Models.Cnn' in switch.

👍

Error When Use CUDA: Unable to load DLL 'DlibDotNetNativeDnn' or one of its dependencies

A simple test to getting face location by Model.Cnn occurred errors when use package FaceRecognitionDotNet.CUDA100.

System.DllNotFoundException: 'Unable to load DLL 'DlibDotNetNativeDnn' or one of its dependencies: The specified module could not be found. (Exception from HRESULT: 0x8007007E)'

Code at git repo https://github.com/chrishaly/FaceDetectionCudaTest

Reproduce:

  1. Create a project with contents:
<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>netcoreapp2.2</TargetFramework>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="FaceRecognitionDotNet.CUDA100" Version="1.2.3.12" />
  </ItemGroup>

  <ItemGroup>
    <None Update="input.jpg">
      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
    </None>
  </ItemGroup>

</Project>
  1. Add code to Program.cs as
using System;
using System.Linq;
using FaceRecognitionDotNet;

namespace FaceDetectionCuda
{
    class Program
    {
        private static FaceRecognition _faceRecognition;

        static void Main(string[] args)
        {
            var modelDirectory = @"D:\dev\dlib-model";
            _faceRecognition = FaceRecognition.Create(modelDirectory); //Exception

            var src = @"input.jpg";
            using (var imageSrc = FaceRecognition.LoadImageFile(src))
            {
                var faceLocations = _faceRecognition.FaceLocations(imageSrc, 0, Model.Cnn).ToArray();
                var faceEncodings = _faceRecognition.FaceEncodings(imageSrc, faceLocations).ToArray();
                Console.WriteLine($"Face count: {faceEncodings.Length}");
            }
        }
    }
}
  1. when run to FaceRecognition.Create exception throws:

System.DllNotFoundException: 'Unable to load DLL 'DlibDotNetNativeDnn' or one of its dependencies: The specified module could not be found. (Exception from HRESULT: 0x8007007E)'

However after change package FaceRecognitionDotNet.CUDA100 to package FaceRecognitionDotNet all run correct.

Missing entry point named 'dnn_cuda_cudaDriverGetVersion' in DLL 'DlibDotNetNativeDnn'

I'm trying to run FaceRecognitionDotNet with Cuda, but I think it seems that I miss some dll files.

The following Exception occurs:

Unhandled Exception: System.EntryPointNotFoundException: Unable to find an entry point named 'dnn_cuda_cudaDriverGetVersion' in DLL 'DlibDotNetNativeDnn'.
at DlibDotNet.NativeMethods.dnn_cuda_cudaDriverGetVersion(Int32& version)
at DlibDotNet.Dnn.Cuda.ThrowCudaException(ErrorType error)
at DlibDotNet.Dnn.LossMmod.Operator[T](IEnumerable1 images, UInt64 batchSize) at FaceRecognitionDotNet.Dlib.Python.CnnFaceDetectionModelV1.Detect(LossMmod net, Image image, Int32 upsampleNumTimes) at FaceRecognitionDotNet.FaceRecognition.FaceLocations(Image image, Int32 numberOfTimesToUpsample, Model model)+MoveNext() at FaceRecognitionDotNet.FaceRecognition.FaceEncodings(Image image, IEnumerable1 knownFaceLocation, Int32 numJitters)+MoveNext()
at System.Collections.Generic.List1.AddEnumerable(IEnumerable1 enumerable)
at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
at FaceDetection.GetDetections(String imageFilePath, FileType fileType, DetectionType detectionType)
at UseFaceDetection.Program.Main(String[] args) in C:\Users\Documents\FaceDetection\FaceDetection\Program.cs:line 45

I obtained the following dll files for cuda: cublas64_92.dll, cudnn64_7.dll, curand64_92.dll and cusolver64_92.dll. (Found in requirements at: https://nugetmusthaves.com/Package/DlibDotNet-WithCUDA)

I figure I am missing or using a wrong reference needed for DlibDotNetNativeDnn. Is there a list of needed Cuda libraries or anything else I might be missing?

Exception loading models.

It appears that the library is unable to load the models.

See the end of this message for details on invoking
just-in-time (JIT) debugging instead of this dialog box.

************** Exception Text **************
System.BadImageFormatException: An attempt was made to load a program with an incorrect format. (Exception from HRESULT: 0x8007000B)
at DlibDotNet.FrontalFaceDetector.Native.get_frontal_face_detector()
at FaceRecognitionDotNet.FaceRecognition..ctor(String directory)
at FaceRecognitionDotNet.FaceRecognition.Create(String directory)
at Temp.Form1.Form1_Shown(Object sender, EventArgs e) in C:\Users\Chris\Desktop\Temp\Temp\Form1.cs:line 47
at System.Windows.Forms.Form.OnShown(EventArgs e)
at System.Windows.Forms.Form.CallShownEvent()
at System.Windows.Forms.Control.InvokeMarshaledCallbackDo(ThreadMethodEntry tme)
at System.Windows.Forms.Control.InvokeMarshaledCallbackHelper(Object obj)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Windows.Forms.Control.InvokeMarshaledCallback(ThreadMethodEntry tme)
at System.Windows.Forms.Control.InvokeMarshaledCallbacks()

************** Loaded Assemblies **************
mscorlib
Assembly Version: 4.0.0.0
Win32 Version: 4.7.3163.0 built by: NET472REL1LAST_C
CodeBase: file:///C:/Windows/Microsoft.NET/Framework/v4.0.30319/mscorlib.dll

Temp
Assembly Version: 1.0.0.0
Win32 Version: 1.0.0.0
CodeBase: file:///C:/Users/Chris/Desktop/Temp/Temp/bin/Debug/Temp.exe

System.Windows.Forms
Assembly Version: 4.0.0.0
Win32 Version: 4.7.3056.0 built by: NET472REL1
CodeBase: file:///C:/WINDOWS/Microsoft.Net/assembly/GAC_MSIL/System.Windows.Forms/v4.0_4.0.0.0__b77a5c561934e089/System.Windows.Forms.dll

System
Assembly Version: 4.0.0.0
Win32 Version: 4.7.3151.0 built by: NET472REL1LAST_B
CodeBase: file:///C:/WINDOWS/Microsoft.Net/assembly/GAC_MSIL/System/v4.0_4.0.0.0__b77a5c561934e089/System.dll

System.Drawing
Assembly Version: 4.0.0.0
Win32 Version: 4.7.3056.0 built by: NET472REL1
CodeBase: file:///C:/WINDOWS/Microsoft.Net/assembly/GAC_MSIL/System.Drawing/v4.0_4.0.0.0__b03f5f7f11d50a3a/System.Drawing.dll

System.Configuration
Assembly Version: 4.0.0.0
Win32 Version: 4.7.3056.0 built by: NET472REL1
CodeBase: file:///C:/WINDOWS/Microsoft.Net/assembly/GAC_MSIL/System.Configuration/v4.0_4.0.0.0__b03f5f7f11d50a3a/System.Configuration.dll

System.Core
Assembly Version: 4.0.0.0
Win32 Version: 4.7.3160.0 built by: NET472REL1LAST_C
CodeBase: file:///C:/WINDOWS/Microsoft.Net/assembly/GAC_MSIL/System.Core/v4.0_4.0.0.0__b77a5c561934e089/System.Core.dll

System.Xml
Assembly Version: 4.0.0.0
Win32 Version: 4.7.3056.0 built by: NET472REL1
CodeBase: file:///C:/WINDOWS/Microsoft.Net/assembly/GAC_MSIL/System.Xml/v4.0_4.0.0.0__b77a5c561934e089/System.Xml.dll

FaceRecognitionDotNet
Assembly Version: 1.2.3.4
Win32 Version: 1.2.3.4
CodeBase: file:///C:/Users/Chris/Desktop/Temp/Temp/bin/Debug/FaceRecognitionDotNet.DLL

netstandard
Assembly Version: 2.0.0.0
Win32 Version: 4.7.3056.0
CodeBase: file:///C:/WINDOWS/Microsoft.Net/assembly/GAC_MSIL/netstandard/v4.0_2.0.0.0__cc7b13ffcd2ddd51/netstandard.dll

DlibDotNet
Assembly Version: 19.15.0.0
Win32 Version: 19.15.0.0
CodeBase: file:///C:/Users/Chris/Desktop/Temp/Temp/bin/Debug/DlibDotNet.DLL

************** JIT Debugging **************
To enable just-in-time (JIT) debugging, the .config file for this
application or computer (machine.config) must have the
jitDebugging value set in the system.windows.forms section.
The application must also be compiled with debugging
enabled.

For example:

When JIT debugging is enabled, any unhandled exception
will be sent to the JIT debugger registered on the computer
rather than be handled by this dialog box.

SEHException: External component has thrown an exception.

Hi i am trying out facerecognition of yours both on console app and web application. I am doing a simple get the distance of two photos on both console and web application here is a more detailed error

[System.Runtime.InteropServices.SEHException (0x80004005): External component has thrown an exception.

at DlibDotNet.ShapePredictor.Native.deserialize_shape_predictor(Byte[] filName)

at DlibDotNet.ShapePredictor.Deserialize(String path)

at FaceRecognitionDotNet.FaceRecognition..ctor(String directory)

at FaceRecognitionDotNet.FaceRecognition.Create(String directory)

at WebApplication2.Pages.IndexModel.OnGet() in C:\Users\user\Source\Repos\WebApplication2\WebApplication2\Pages\Index.cshtml.cs:line 17

at Microsoft.AspNetCore.Mvc.RazorPages.Internal.ExecutorFactory.VoidHandlerMethod.Execute(Object receiver, Object[] arguments)

at Microsoft.AspNetCore.Mvc.RazorPages.Internal.PageActionInvoker.InvokeHandlerMethodAsync()

at Microsoft.AspNetCore.Mvc.RazorPages.Internal.PageActionInvoker.InvokeNextPageFilterAsync()

at Microsoft.AspNetCore.Mvc.RazorPages.Internal.PageActionInvoker.Rethrow(PageHandlerExecutedContext context)

at Microsoft.AspNetCore.Mvc.RazorPages.Internal.PageActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)

at Microsoft.AspNetCore.Mvc.RazorPages.Internal.PageActionInvoker.InvokeInnerFilterAsync()

at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeNextResourceFilter()

at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.Rethrow(ResourceExecutedContext context)

at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)

at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeFilterPipelineAsync()

at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeAsync()

at Microsoft.AspNetCore.Builder.RouterMiddleware.Invoke(HttpContext httpContext)

at Microsoft.AspNetCore.StaticFiles.StaticFileMiddleware.Invoke(HttpContext context)

at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context)](url)

Emgucv&OpencvSharp

Hi:
Thank you for providing such a good lib.
I retrieve the video frame by emgucv and opencvsharp, want to use the same idea to detect faces also. But i dont got datas of the type DlibDotNet.Rectangle[] on opencvsharp, What should I do? The code is as follows:

    public System.Drawing.Image FaceRecognize(Mat imageFrame)
    {
        System.Drawing.Image bi = null;
        Mat tempImg = imageFrame;
        byte[] array = tempImg.ToBytes();
        System.Drawing.Image image = byteToImage(array);
        BitmapImage bImg = BitmapToBitmapImage(BytesToBitmap(imageFrame.ToBytes()));

        Mat grayImage = new Mat();
        Cv2.CvtColor(tempImg, grayImage, ColorConversionCodes.RGB2GRAY);
        Cv2.EqualizeHist(grayImage, grayImage);

        using (var imageArray = Dlib.LoadImageData<byte>(grayImage.ToBytes(), (uint)bImg.PixelHeight, (uint)bImg.PixelWidth, (uint)bImg.PixelWidth))
        {
            DlibDotNet.Rectangle[] faces = faceDetector.Operator(imageArray);

            foreach (var item in faces)
            {
                Dlib.DrawRectangle(imageArray, item, new RgbPixel(0, 0, 255));
            }
        }
        bi = byteToImage(imageFrame.ToBytes());
        return bi;
    }`

How to realize in real time face detection?

Sorry, I have a question for FaceRecognitionDotNet. As far as I know, for python we could use "ret, frame = video_capture.read()" to get frame and input into face_locations to realize real time detect.
For FaceRecognitionDotNet, we have to nominate the specific image path, sorry for my stupid, I tried a lot of times, still can not find a good way to input bytes or array , or transfer bytes or array into Image into FaceLocations instead of image path .Please author can answer my question. thanks

Error in FaceRecognition.Create() on MacOS

FaceRecognition fr = FaceRecognition.Create(directory);

"Unable to load DLL DlibDotNet.Native.dll The specified module or one of its dependencies could not be found"

Compatible with Xamarin?

I am wondering if the FaceRecognitionDotNet nuget package is compatible with Xamarin?
Running the application in a console app it all works fine, but running it in a Xamarin app (Xamarin Forms, but deploying it on Android) the following error occurs:

Running:
faceRecognition = FaceRecognition.Create(directoryInfo.FullName);

gives the following error:

System.DllNotFoundException: DlibDotNetNative

But the Dll's are in the output folders:
image

It seems like the dll's are not included in the .sdk file.
Which is where it is looking for the libraries I suppose.

TypeInitializationException the type initializer for "FaceRecognitionDotNet" threw an exception

hi, I am running a TypeInitializationException error on some computers.
I found that if I didn't install visual studio (2019) on my computer, I would get an error.
After installing the C# programming environment, it will run normally, but it will still run normally after uninstalling visual studio completely. Can you help me see what is going on?

Environment: 64-bit win7 and win10
Release: 64 bit

Thank you

TIM截图20190617145542

Get face encodings

Hello, i am trying to get the face encoding with this codes
var bidenFile = "480px-Biden_2013.jpg"; var path1 = Path.Combine(Directory.GetCurrentDirectory(), bidenFile); var image = FaceRecognition.LoadImageFile(path1); FaceEncoding[] encodings = _FaceRecognition.FaceEncodings(image).ToArray();
what i am trying to do here is to get the actual array of the face encoding but on the foreach loop
foreach (var enc in encodings) { Console.WriteLine(enc); }
it displays this FaceRecognitionDotNet.FaceEncoding i am looking to get the actual face encoding such as { -0.33578} and so on and i will actually save it on my sql lite as a form of enrollment for facial recognition and pull the encodings when its time to perform facial recognition

can you guide me on how to get the necessary value thank you

kernel32

Hello takuya-takeuchi, I reminded you that I needed kernel32.dll when building the project.
Where can I get it, please? Thank you.

Can I open these projects in VS2015?

My office environment only have the VS2015, and at current I don't want to upgrade to VS2017.
But when I open the solution FaceRecognitionDotNet in the VS2015, the projects always loaded fail.
The error as following:
"FaceEncodingPerformance.csproj : error : The default XML namespace of the project must be the MSBuild XML namespace. If the project is authored in the MSBuild 2003 format, please add xmlns="http://schemas.microsoft.com/developer/msbuild/2003" to the element. If the project has been authored in the old 1.0 or 1.2 format, please convert it to MSBuild 2003 format."
I have install the .net core sdk2.2 and the nuget.exe 3.6.0. But I still can't work.
Is it really the .net standard2.0 project can't load in the vs2015?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.