takuya-takeuchi / FaceRecognitionDotNet

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

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Unable to read the face

guruprakashchinnasamy opened this issue · comments

e5066894266fccbf9e1238ef5c5da0fa
Sadhguru

I'm unable to read the face of above pictures.

ERROR: "Sequence contains no elements"

@guruprakashchinnasamy

You can change parameter for FaceLocations method.

using System;
using System.Collections.Generic;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using FaceRecognitionDotNet;

namespace Issue
{

    class Program
    {

        private static void Main(string[] args)
        {
            var fileA = "120229055-fbfdc900-c269-11eb-8a05-174dc4a786b9.jpg";
            var fileB = "120229066-015b1380-c26a-11eb-82ba-601914559fc0.jpg";
            var modelDir = Environment.GetEnvironmentVariable("FaceRecognitionDotNetModelDir");
            using var fr = FaceRecognition.Create(modelDir);
            Detect(fr, fileA, fileB, Model.Hog);
            Detect(fr, fileA, fileB, Model.Cnn);
        }

        private static void Detect(FaceRecognition fr, string fileA, string fileB, Model model)
        {
            using var imageA = FaceRecognition.LoadImageFile(fileA);
            using var imageB = FaceRecognition.LoadImageFile(fileB);
            IEnumerable<Location> locationA = null;
            IEnumerable<Location> locationB = null;
            switch(model)
            {
                case Model.Cnn:
                    locationA = fr.FaceLocations(imageA, 0, model);
                    locationB = fr.FaceLocations(imageB, 0, model);
                    break;
                case Model.Hog:
                    locationA = fr.FaceLocations(imageA);
                    locationB = fr.FaceLocations(imageB);
                    break;
            }
            
            if (!locationA.Any())
                Console.WriteLine($"{fileA} has no faces by {model}");
            else
                Console.WriteLine($"{fileA}: {ToString(locationA.First())} by {model}");
            if (!locationB.Any())
                Console.WriteLine($"{fileB} has no faces by {model}");
            else
                Console.WriteLine($"{fileB}: {ToString(locationB.First())} by {model}");
        }

        private static string ToString(FaceRecognitionDotNet.Location location)
        {
            return $"{location.Left}, {location.Top}, {location.Right}, {location.Bottom}";
        }

    }

}
dotnet run -c Release
120229055-fbfdc900-c269-11eb-8a05-174dc4a786b9.jpg has no faces by Hog
120229066-015b1380-c26a-11eb-82ba-601914559fc0.jpg has no faces by Hog
120229055-fbfdc900-c269-11eb-8a05-174dc4a786b9.jpg: 274, 289, 557, 572 by Cnn
120229066-015b1380-c26a-11eb-82ba-601914559fc0.jpg: 239, 235, 579, 575 by Cnn

And I tried to detect face by face_recognition.

(face_recognition) D:\Works\OpenSource\Temp\FaceRecognitionDotNet\14.#173>python find_faces_in_picture.py
I found 0 face(s) in this photograph.
(face_recognition) D:\Works\OpenSource\Temp\FaceRecognitionDotNet\14.#173>python find_faces_in_picture_cnn.py
I found 1 face(s) in this photograph.
A face is located at pixel location Top: 289, Left: 274, Bottom: 572, Right: 557

(face_recognition) D:\Works\OpenSource\Temp\FaceRecognitionDotNet\14.#173>python find_faces_in_picture.py
I found 0 face(s) in this photograph.
(face_recognition) D:\Works\OpenSource\Temp\FaceRecognitionDotNet\14.#173>python find_faces_in_picture_cnn.py
I found 1 face(s) in this photograph.
A face is located at pixel location Top: 235, Left: 239, Bottom: 575, Right: 579

They can reproduce same results.