public static string GetMostAcurateFace(SimilarFaces[] array) { int length = array.Length; float faceASimilarity = array[0].Similarity; for (int i = 1; i < length; i++) { float faceBSimilarity = array[i].Similarity; if (faceASimilarity < faceBSimilarity) { faceASimilarity = faceBSimilarity; } } SimilarFaces F = (from f in array where f.Similarity == faceASimilarity select f).SingleOrDefault(); //for (int j = i + 1; j < length; j++) //{ // if (array[i].Similarity > array[j].Similarity) // { // temp = array[i].Similarity; // array[i].Similarity = array[j].Similarity; // array[j].Similarity = temp; // } //} return(F.FullName); }
public void GetPerson(TFaceRecord faceIn, out string FaceFullName) { bool ok = false; string fName = "Unknown Face"; if (Global.Persons == null) { FaceFullName = fName; return; } try { float Threshold = 0.034455f; //float Threshold = 0.001155f; SimilarFaces[] Faces = null; SimilarFaces[] faces = new SimilarFaces[Global.Persons.Length]; List <SimilarFaces> Fa = new List <SimilarFaces>(); int i = -1; foreach (TFaceRecord fac in Global.Persons) { TFaceRecord F = new TFaceRecord(); F = fac; float Similarity = 0.0f; FSDK.MatchFaces(ref faceIn.Template, ref F.Template, ref Similarity); if (Similarity >= Threshold) { i++; faces[i].FullName = fac.Fullname; faces[i].Similarity = Similarity; } } if (faces != null) { Faces = faces.Where(v => v.FullName != null).ToArray(); fName = GetMostAcurateFace(Faces); //fName = SortSimilarFaces(Faces)[0].FullName; } } catch (Exception n) { } FaceFullName = fName; //return ok; }
public bool GetPerson(TFaceRecord faceIn, out TFaceRecord faceOut) { bool ok = false; TFaceRecord f = new TFaceRecord(); if (Global.Persons == null) { faceOut = f; return(ok); } try { float Threshold = 0.001155f; //FSDK.GetMatchingThresholdAtFAR(0.0009f, ref Threshold); List <float> sFaces = new List <float>(); SimilarFaces[] Faces = null; SimilarFaces[] faces = new SimilarFaces[Global.Persons.Length]; int i = -1; foreach (TFaceRecord fac in Global.Persons.AsParallel()) { TFaceRecord F = new TFaceRecord(); F = fac; float Similarity = 0.0f; //0.000026273356E == 0.00228634826 FSDK.MatchFaces(ref faceIn.Template, ref F.Template, ref Similarity); if (Similarity >= Threshold) { i++; faces[i].FullName = fac.Fullname; faces[i].Similarity = Similarity; ok = true; f = fac; break; } } //Faces.OrderByDescending<SimilarFaces,> //Parallel.ForEach(Global.Persons.AsParallel(), fac => // { // float Similarity = 0.0f; // FSDK.MatchFaces(ref faceIn.Template, ref fac.Template, ref Similarity); // if (Similarity >= Threshold) // { // ok = true; // f = fac; // } // }); } catch (Exception n) { } faceOut = f; return(ok); }