Comments (9)
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.
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.
@takuya-takeuchi It works now , thanks!
from facerecognitiondotnet.
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.
@aventurella
Exactly. We use https://github.com/ageitgey/face_recognition_models
from facerecognitiondotnet.
This sentence can not be passed KeyValuePair<string, FaceEncoding>[] array1 = new \u003C\u003Ef__AnonymousType0<string, string>[6]
from facerecognitiondotnet.
@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以上来源是由反汇编产生的。所以源代码有一些腐败。
KeyValuePair<string, FaceEncoding>[] array1 = new \u003C\u003Ef__AnonymousType0<string, string>[6]
至
KeyValuePair<string, FaceEncoding>[] array1 = new []
OK ,thank you
from facerecognitiondotnet.
It seem like to be able to close.
from facerecognitiondotnet.
Related Issues (20)
- Getting Started guide
- Use Cases supported
- Performance Matrix
- UnhandledException: System.TypeInitializationException: The type initializer for 'DlibDotNet.NativeMethods' threw an exception. HOT 3
- Refactor System.Drawing out of the project HOT 6
- Getting started on GPU is few
- System.Runtime.InteropServices.SEHException (0x80004005): External component has thrown an exception. HOT 4
- GOOD
- Dlib.LoadImage is unable to read images from image library (even when capabity granted) HOT 4
- Will this run faster than the python version? HOT 1
- Provide an overload with SkiaSharp Bitmap to use it on Net7/Linux? HOT 1
- Unexpected version found while deserializing dlib::add_skip_layer when load Emotion Estimator Model
- Could you please provide FaceRecognitionDotNet that supports x86?
- Training Duration HeadPose HOT 1
- Bug: HeadPose.Equals throws NullReferenceException
- Can you merge LoadImage for SkiaSharp in main?
- how to know face size from FaceEncoding Object?
- Not Find ProjectDlibDotNet
- building the tools dll
- Illegal Instruction em computadores windows
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from facerecognitiondotnet.