Giter VIP home page Giter VIP logo

Comments (9)

Webreaper avatar Webreaper commented on May 12, 2024 1

Feels like you should include this in the main repo - it's quite hard to find this issue, and for a project called FaceRecognitionDotnet to not have an actual example of facial recognition in the master branch seems somewhat counter-intuitive. :)

from facerecognitiondotnet.

takuya-takeuchi avatar takuya-takeuchi commented on May 12, 2024

Sorry. I lost the above sample source code. But I was disassemble the above problem. (But not equal completely).
You must add OpenCVSharp, collect image and override image path string.

private static void Main(string[] args)
    {
      FaceRecognition fr = FaceRecognition.Create("D:\\Works\\Local\\face_recognition_models\\face_recognition_models\\models");
      using (Image image1 = FaceRecognition.LoadImageFile("images\\AP_090107018039.jpg"))
      {
        KeyValuePair<string, FaceEncoding>[] array1 = new \u003C\u003Ef__AnonymousType0<string, string>[6]
        {
          new
          {
            Path = "images\\BarackObama.jpg",
            Name = "Barack Obama"
          },
          new
          {
            Path = "images\\BillClinton.jpg",
            Name = "Bill Clinton"
          },
          new
          {
            Path = "images\\GeorgeWBush.jpeg",
            Name = "George W Bush"
          },
          new
          {
            Path = "images\\GeorgeH.W.Bush.jpg",
            Name = "George H W Bush"
          },
          new
          {
            Path = "images\\JimmyCarter.jpg",
            Name = "Jimmy Carter"
          },
          new{ Path = "images\\ShinzoAbe.jpg", Name = "Shinzo Abe" }
        }.Select(arg =>
        {
          using (Image image = FaceRecognition.LoadImageFile(arg.Path))
            return new KeyValuePair<string, FaceEncoding>(arg.Name, fr.FaceEncodings(image, (IEnumerable<Location>) null, 0).FirstOrDefault<FaceEncoding>());
        }).ToArray<KeyValuePair<string, FaceEncoding>>();
        Dictionary<string, Dictionary<Location, double>> dictionary1 = new Dictionary<string, Dictionary<Location, double>>();
        foreach (Location faceLocation in fr.FaceLocations(image1, 1, Models.Hog))
        {
          FaceEncoding[] array2 = fr.FaceEncodings(image1, (IEnumerable<Location>) new Location[1]
          {
            faceLocation
          }, 0).ToArray<FaceEncoding>();
          foreach (KeyValuePair<string, FaceEncoding> keyValuePair in ((IEnumerable<KeyValuePair<string, FaceEncoding>>) array1).Where<KeyValuePair<string, FaceEncoding>>((Func<KeyValuePair<string, FaceEncoding>, bool>) (pair => pair.Value != null)))
          {
            double num = FaceRecognition.FaceDistance(((IEnumerable<FaceEncoding>) array2).First<FaceEncoding>(), keyValuePair.Value);
            if (num < 0.6)
            {
              Dictionary<Location, double> dictionary2;
              if (!dictionary1.TryGetValue(keyValuePair.Key, out dictionary2))
              {
                dictionary2 = new Dictionary<Location, double>();
                dictionary1.Add(keyValuePair.Key, dictionary2);
              }
              dictionary2.Add(faceLocation, num);
            }
          }
          foreach (FaceEncoding faceEncoding in array2)
            faceEncoding.Dispose();
        }
        using (Mat mat1 = Cv2.ImRead("images\\AP_090107018039.jpg", ImreadModes.Color))
        {
          using (Mat mat2 = mat1.Resize(Size.Zero, 1.0, 1.0, InterpolationFlags.Linear))
          {
            foreach (KeyValuePair<string, Dictionary<Location, double>> keyValuePair1 in dictionary1)
            {
              string key = keyValuePair1.Key;
              Dictionary<Location, double> dictionary2 = keyValuePair1.Value;
              Location location = (Location) null;
              double maxValue = double.MaxValue;
              foreach (KeyValuePair<Location, double> keyValuePair2 in dictionary2)
              {
                if (keyValuePair2.Value < maxValue)
                {
                  maxValue = keyValuePair2.Value;
                  location = keyValuePair2.Key;
                }
              }
              Point point = new Point((double) location.Left * 1.0, (double) location.Top * 1.0);
              Point pt2 = new Point((double) location.Right * 1.0, (double) location.Bottom * 1.0);
              mat2.Rectangle(point, pt2, Scalar.Red, 2, LineTypes.AntiAlias, 0);
              point.Y = pt2.Y - 20;
              mat2.Rectangle(point, pt2, Scalar.Red, -1, LineTypes.AntiAlias, 1);
              point.X += 3;
              point.Y = pt2.Y - 5;
              mat2.PutText(key, point, HersheyFonts.HersheySimplex, 0.4, Scalar.White, 1, LineTypes.Link8, false);
            }
            Cv2.ImShow("Result", mat2);
            Cv2.WaitKey(0);
          }
        }
      }
    }
  }

from facerecognitiondotnet.

jrt324 avatar jrt324 commented on May 12, 2024

@takuya-takeuchi It works now , thanks!

from facerecognitiondotnet.

theladyjaye avatar theladyjaye commented on May 12, 2024

In your example, where did you acquire the model files from?

D:\\Works\\Local\\face_recognition_models\\face_recognition_models\\models

https://github.com/ageitgey/face_recognition_models?
https://pypi.org/project/face_recognition_models/

from facerecognitiondotnet.

takuya-takeuchi avatar takuya-takeuchi commented on May 12, 2024

@aventurella
Exactly. We use https://github.com/ageitgey/face_recognition_models

from facerecognitiondotnet.

feelsyt avatar feelsyt commented on May 12, 2024

This sentence can not be passed KeyValuePair<string, FaceEncoding>[] array1 = new \u003C\u003Ef__AnonymousType0<string, string>[6]

from facerecognitiondotnet.

takuya-takeuchi avatar takuya-takeuchi commented on May 12, 2024

@feelsyt The above source was produced by disassemble. So source code has some corruption.

KeyValuePair<string, FaceEncoding>[] array1 = new \u003C\u003Ef__AnonymousType0<string, string>[6]

to

KeyValuePair<string, FaceEncoding>[] array1 = new []

from facerecognitiondotnet.

feelsyt avatar feelsyt commented on May 12, 2024

@feelsyt以上来源是由反汇编产生的。所以源代码有一些腐败。

KeyValuePair<string, FaceEncoding>[] array1 = new \u003C\u003Ef__AnonymousType0<string, string>[6]

KeyValuePair<string, FaceEncoding>[] array1 = new []

OK ,thank you

from facerecognitiondotnet.

takuya-takeuchi avatar takuya-takeuchi commented on May 12, 2024

It seem like to be able to close.

from facerecognitiondotnet.

Related Issues (20)

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.