async Task <ViewQueryResponse <string> > GetPersonListAsync() { List <MyPerson> database = new List <MyPerson>(); string sourceDirectory = @"/Users/chrisk/source/KiwiRest/RestFiles/App_Data/files"; AfisEngine Afis = new AfisEngine(); DateTime date1 = DateTime.Now; Console.WriteLine("Starting PersonList: " + date1); WebClient client = new WebClient(); string uri = "http://localhost:5984/prints/_all_docs&include_docs=true"; // string data = client.DownloadString (uri); // var fromJson = JsonSerializer.DeserializeFromString<AllDocs>(data); var myCouchClient = new MyCouch.MyCouchClient("http://localhost:5984/prints"); ViewQueryResponse <string> result = null; try { var queryView = new QueryViewRequest("_all_docs"); queryView.Configure(query => query .IncludeDocs(true)); result = await myCouchClient.Views.QueryAsync <string>(queryView); } catch (Exception e) { } return(result); }
static void Main(string[] args) { Afis = new AfisEngine(); AFISMain afis = new AFISMain(); afis.ShowDialog(); } // end Main
public void RegisterUser(string b64, string UserId) { AfisEngine afis = new AfisEngine(); Database Db = new Database(); Person probe = new Person(); Fingerprint fp = new Fingerprint(); int Uid = Convert.ToInt16(UserId); //create image on harddrive byte[] imageBytes = Convert.FromBase64String(b64); fp.AsBitmap = CreateBmpImage(imageBytes); probe.Fingerprints.Add(fp); afis.Extract(probe); byte[] template = fp.Template; using (SqlCommand cmd = new SqlCommand("EnrollFaculty", Db.ConnectFingerDb())) { cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@FingerImage", imageBytes); cmd.Parameters.AddWithValue("@FingerTemplate", template); cmd.Parameters.AddWithValue("@UserId", Uid); cmd.ExecuteNonQuery(); } }
public void Clone() { Fingerprint fp1 = new Fingerprint(); fp1.AsBitmap = Settings.SomeFingerprint; fp1.Finger = Finger.RightThumb; AfisEngine afis = new AfisEngine(); afis.Extract(new Person(fp1)); Assert.IsNotNull(fp1.Template); Fingerprint fp2 = fp1.Clone(); Assert.AreEqual(fp1.Image, fp2.Image); Assert.AreEqual(Finger.RightThumb, fp2.Finger); Assert.AreEqual(fp1.Template, fp2.Template); Fingerprint fp3 = new Fingerprint().Clone(); Assert.IsNull(fp3.Image); Assert.AreEqual(Finger.Any, fp3.Finger); Assert.IsNull(fp3.Template); Fingerprint fp4 = (fp2 as ICloneable).Clone() as Fingerprint; Assert.AreEqual(fp1.Image, fp4.Image); Assert.AreEqual(Finger.RightThumb, fp4.Finger); Assert.AreEqual(fp1.Template, fp4.Template); }
static void insertaHuellasDesdeCarpeta() { // Inicializa la carpeta de imagenes //DirectoryInfo di = new DirectoryInfo(@"C:\Users\PC_STE_19\Documents\Visual Studio 2015\Projects\BiometricFinger\images"); DirectoryInfo di = new DirectoryInfo(@"C:\Users\PC_STE_19\Desktop\DEDOS_SECUGEN"); Console.WriteLine("No search pattern returns:"); List <Usuario> usuarios = new List <Usuario>(); using (var context = new db_Entidades()) { foreach (var fi in di.GetFiles()) { AfisEngine Afis = new AfisEngine(); //Bitmap image1 = (Bitmap)Image.FromFile(@"C:\Users\PC_STE_19\Documents\Visual Studio 2015\Projects\BiometricFinger\images\" + fi.Name, true); Bitmap image1 = (Bitmap)Image.FromFile(@"C:\Users\PC_STE_19\Desktop\DEDOS_SECUGEN\" + fi.Name, true); Fingerprint f = new Fingerprint(); f.AsBitmap = image1; Usuario usu = new Usuario(); Person persona = new Person(); persona.Fingerprints.Add(f); Afis.Extract(persona); usu.username = fi.Name; usu.finger = f.AsIsoTemplate; usuarios.Add(usu); Console.WriteLine(fi.Name); context.Usuario.Add(usu); } context.SaveChanges(); } }
static void test() { AfisEngine Afis = new AfisEngine(); Afis.Threshold = (float)100.12; Console.WriteLine(Afis.Threshold.ToString()); string files1 = @"C:\Users\Mihir Gajjar\Desktop\DSP_Final\FingerPrint\FingerPrint\Database\1_1.bmp"; string files2 = @"C:\Users\Mihir Gajjar\Desktop\DSP_Final\FingerPrint\FingerPrint\Database\1_2.bmp"; Fingerprint fp1 = new Fingerprint(); fp1.AsBitmapSource = new BitmapImage(new Uri(files1, UriKind.RelativeOrAbsolute)); Fingerprint fp2 = new Fingerprint(); fp2.AsBitmapSource = new BitmapImage(new Uri(files2, UriKind.RelativeOrAbsolute)); Person person1 = new Person(); person1.Fingerprints.Add(fp1); Person person2 = new Person(); person2.Fingerprints.Add(fp2); Afis.Extract(person1); Afis.Extract(person2); float score = Afis.Verify(person1, person1); bool match = (score > Afis.Threshold); Console.WriteLine(score.ToString()); string temp = Console.ReadLine(); }
public bool Verify(byte[] bitmap, string template) { AfisEngine Afis = new AfisEngine(); Afis.Threshold = Treshold; Stream bitmapStream = new MemoryStream(bitmap); Fingerprint fp1 = new Fingerprint(); fp1.AsBitmap = new Bitmap(bitmapStream); Person p1 = new Person(); p1.Fingerprints.Add(fp1); Afis.Extract(p1); Fingerprint fp2 = new Fingerprint(); fp2.AsXmlTemplate = XElement.Parse(template); Person p2 = new Person(); p2.Fingerprints.Add(fp2); float score = Afis.Verify(p1, p2); Console.WriteLine("Matching score " + score + " - fingerprints " + (score > 0 ? "match" : "do not match")); Console.WriteLine("Biometrics Match Treshold used: " + Treshold); return(score > 0); }
public void DefaultConstructor() { AfisEngine afis = new AfisEngine(); Assert.AreEqual(500, afis.Dpi); Assert.AreEqual(1, afis.MinMatches); Assert.That(afis.Threshold > 0); }
public UserManager() { // Look up the probe using Threshold = 10 afis = new AfisEngine(); afis.Threshold = 25; db = new UserDB(); }
public async Task <ActionResult> ManCreate([Bind(Include = "Name, Filename")] mortal mortal) { AfisEngine Afis = new AfisEngine(); Afis.Threshold = 180; var myExport = new CsvExport(); string apppath = System.IO.Path.Combine(Server.MapPath("~"), "images"); for (int i = 0; i < 40; i++) { string pathToImageO = (System.IO.Path.Combine(apppath, "original/" + (i + 1).ToString() + ".png")); for (int j = 0; j < 40; j++) { string pathToImageM2 = (System.IO.Path.Combine(apppath, "augmented/" + (j + 1).ToString() + ".jpg")); Fingerprint fp1 = new Fingerprint(); Fingerprint fp2 = new Fingerprint(); MyPerson personO = new MyPerson(); MyPerson personM = new MyPerson(); Bitmap bitmap1 = fp1.AsBitmap = new Bitmap(Image.FromFile(pathToImageO)); Bitmap bitmap2 = fp2.AsBitmap = new Bitmap(Image.FromFile(pathToImageM2)); personO.Fingerprints.Add(fp1); personM.Fingerprints.Add(fp2); Afis.Extract(personO); Afis.Extract(personM); float score = Afis.Verify(personO, personM); if (score > Afis.Threshold) { myExport.AddRow(); myExport["Theshold"] = Afis.Threshold; myExport["Match"] = 1; myExport["FingerprintO"] = i + 1; myExport["FingerprintM"] = j + 1; } else { myExport.AddRow(); myExport["Theshold"] = Afis.Threshold; myExport["Match"] = 0; myExport["FingerprintO"] = i + 1; myExport["FingerprintM"] = j + 1; } } } ///ASP.NET MVC action example return(File(myExport.ExportToBytes(), "text/csv", "results(180).csv")); //return View(); //Response.Write("<script>alert('Please Enter Filename');</script>"); }
protected void Page_Load(object sender, EventArgs e) { probe = new Person(); probe = Des(); sfis = new AfisEngine(); candidate = new Person(); fp = new Fingerprint(); //sfis.Threshold = 11; }
public static List <MyPerson> GetPersonList() { List <MyPerson> database = new List <MyPerson>(); string sourceDirectory = @"/Users/chrisk/source/KiwiRest/RestFiles/App_Data/files"; AfisEngine Afis = new AfisEngine(); DateTime date1 = DateTime.Now; Console.WriteLine("Starting PersonList: " + date1); WebClient client = new WebClient(); string uri = "http://localhost:5984/prints/_all_docs&include_docs=true"; // string data = client.DownloadString (uri); // var fromJson = JsonSerializer.DeserializeFromString<AllDocs>(data); var myCouchClient = new MyCouch.MyCouchClient("http://localhost:5984/prints"); try { var queryView = new QueryViewRequest("_all_docs"); queryView.Configure(query => query .IncludeDocs(true)); } catch (Exception e) { } try { var files = Directory.EnumerateFiles(sourceDirectory, "*.png"); foreach (string currentFile in files) { DateTime date3 = DateTime.Now; Console.WriteLine("Processing " + currentFile + " at " + date3); string fileName = currentFile.Substring(sourceDirectory.Length + 1); // Directory.Move(currentFile, Path.Combine(archiveDirectory, fileName)); Guid g = Guid.NewGuid(); var guidStr = g.ToString(); MyPerson probe = SourceAfisIdentify.Enroll(currentFile, guidStr, Afis); Console.WriteLine("Adding " + guidStr); DateTime date4 = DateTime.Now; Console.WriteLine("Processed " + currentFile + " at " + date4 + " uuid: " + guidStr); var diffInSeconds = (date4 - date3).TotalSeconds; Console.WriteLine("Finished " + guidStr + " at " + date4 + " Total time: " + diffInSeconds + " seconds"); database.Add(probe); } DateTime date2 = DateTime.Now; var diffInSeconds2 = (date2 - date1).TotalSeconds; Console.WriteLine("Finished PersonList at " + date2 + " Total time: " + diffInSeconds2 + " seconds"); } catch (Exception e) { Console.WriteLine(e.Message); } return(database); }
/// <summary> /// Verify a candidates fingerprint /// </summary> /// <param name="c">The candidate to compare against</param> /// <param name="fp">The provided fingerprint</param> /// <returns>A float from 0 to 100 which represents the strength of the fingerprint match. Higher is better.</returns> public static float VerifyFingerprint(Candidate c, Fingerprint fp) { var afis = new AfisEngine(); var test = new Person(fp); afis.Extract(test); var candidate = new Person(c.Fingerprint); return(afis.Verify(candidate, test)); }
}//getMatch //Match probe with people in the database public static Match getMatch(string fingerName, System.Drawing.Image fingerImage, string visitorId, Int32 threshold) { if (Afis == null) { Afis = new AfisEngine(); } Match match = new Match(); // Match visitor with unknown identity MyPerson probe = getProbe(fingerName, fingerImage, visitorId); if (persons == null) { // Load all people fron database DataAccess dataAccess = new DataAccess(); persons = dataAccess.retrievePersonFingerprintTemplates(); Console.WriteLine("###-->> Loading persons from DB. Total persons = " + persons.Count()); } else { Console.WriteLine("###-->> Loading persons from Cache. Total persons = " + persons.Count()); } // Look up the probe using Threshold = 10 Afis.Threshold = threshold; Console.WriteLine("Identifying {0} in database of {1} persons...", probe.Name, persons.Count); MyPerson matchedPerson = Afis.Identify(probe, persons).FirstOrDefault() as MyPerson; // Null result means that there is no candidate with similarity score above threshold if (matchedPerson == null) { match.setProbe(probe); match.setMatchedPerson(matchedPerson); match.setStatus(false); match.setScore(0.0F); return(match); } // Compute similarity score float score = Afis.Verify(probe, matchedPerson); match.setProbe(probe); match.setMatchedPerson(matchedPerson); match.setStatus(true); match.setScore(score); Console.WriteLine("Similarity score between {0} and {1} = {2:F3}", probe.Name, matchedPerson.Name, score); Console.WriteLine("Visitor " + visitorId + " matches with registered person " + matchedPerson.Name + ". Match score = " + score); return(match); }//getMatch
public void FingerTest() { AfisEngine afis = new AfisEngine(); afis.Threshold = 0.0001f; Person person1 = new Person(new Fingerprint() { AsBitmap = Settings.SomeFingerprint }); afis.Extract(person1); Person person2 = new Person(new Fingerprint() { AsBitmap = Settings.MatchingFingerprint }); afis.Extract(person2); person1.Fingerprints[0].Finger = Finger.RightThumb; Assert.AreEqual(Finger.RightThumb, person1.Fingerprints[0].Finger); person2.Fingerprints[0].Finger = Finger.RightThumb; Assert.That(afis.Verify(person1, person2) > 0); Assert.That(afis.Identify(person1, new[] { person2 }).Count() > 0); person2.Fingerprints[0].Finger = Finger.LeftIndex; Assert.That(afis.Verify(person1, person2) == 0); Assert.That(afis.Identify(person1, new[] { person2 }).Count() == 0); person1.Fingerprints[0].Finger = Finger.Any; Assert.That(afis.Verify(person1, person2) > 0); Assert.That(afis.Verify(person2, person1) > 0); Assert.That(afis.Identify(person1, new[] { person2 }).Count() > 0); Assert.That(afis.Identify(person2, new[] { person1 }).Count() > 0); person2.Fingerprints[0].Finger = Finger.Any; Assert.That(afis.Verify(person1, person2) > 0); Assert.That(afis.Identify(person1, new[] { person2 }).Count() > 0); Person person3 = new Person(new Fingerprint() { AsBitmap = Settings.MatchingFingerprint }); afis.Extract(person3); person1.Fingerprints[0].Finger = Finger.LeftIndex; person2.Fingerprints[0].Finger = Finger.LeftIndex; person3.Fingerprints[0].Finger = Finger.RightMiddle; CollectionAssert.AreEqual(afis.Identify(person1, new[] { person2, person3 }), new[] { person2 }); person1.Fingerprints[0].Finger = Finger.RightMiddle; CollectionAssert.AreEqual(afis.Identify(person1, new[] { person2, person3 }), new[] { person3 }); Assert.Catch(() => { person1.Fingerprints[0].Finger = (Finger)(-1); }); }
public async Task <ActionResult> Create([Bind(Include = "logId,mortalId,dateTime_2,areaCode")] log log, FormCollection collection) { string fileNameInput = collection["filename"]; AfisEngine Afis = new AfisEngine(); Afis.Threshold = 10; Fingerprint fp1 = new Fingerprint(); string apppath = System.IO.Path.Combine(Server.MapPath("~"), "images"); string pathToImage = (System.IO.Path.Combine(apppath, fileNameInput)); Bitmap bitmap = fp1.AsBitmap = new Bitmap(Image.FromFile(pathToImage)); MyPerson personsdk = new MyPerson(); personsdk.Fingerprints.Add(fp1); Afis.Extract(personsdk); string sql = "Select * from mortal"; List <mortal> personListRom = db.mortals.SqlQuery(sql).ToList(); List <MyPerson> personListRam = new List <MyPerson>(); foreach (mortal p in personListRom) { MyPerson personTemp = new MyPerson(); MyFingerprint fpTemp = new MyFingerprint(); personTemp.Id = p.mortalId; personTemp.Name = p.name; fpTemp.Filename = p.filename; fpTemp.AsXmlTemplate = XElement.Parse(p.template); personTemp.Fingerprints.Add(fpTemp); personListRam.Add(personTemp); } MyPerson match = Afis.Identify(personsdk, personListRam).FirstOrDefault() as MyPerson; log.mortalId = match.Id; if (ModelState.IsValid) { db.logs.Add(log); await db.SaveChangesAsync(); return(RedirectToAction("Index")); } ViewBag.mortalId = new SelectList(db.mortals, "mortalId", "name", log.mortalId); return(View(log)); }
public static bool Finger(String candidate_fingerprint, String candidate_name, String probe_fingerprint, String probe_name) { // Initialize SourceAFIS Afis = new AfisEngine(); // Enroll some people List <MyPerson> database = new List <MyPerson>(); database.Add(Enroll(candidate_fingerprint, candidate_name)); // Save the database to disk and load it back, just to try out the serialization BinaryFormatter formatter = new BinaryFormatter(); using (Stream stream = File.Open("database.dat", FileMode.Create)) formatter.Serialize(stream, database); //Reloading Database using (FileStream stream = File.OpenRead("database.dat")) database = (List <MyPerson>)formatter.Deserialize(stream); // Enroll visitor with unknown identity MyPerson probe = Enroll(probe_fingerprint, probe_name); // Look up the probe using Threshold = 10 Afis.Threshold = 60; //TEST CASE //MessageBox.Show(String.Format("Identifying {0} in database of {1} persons...", probe.Name, database.Count)); MyPerson match = Afis.Identify(probe, database).FirstOrDefault() as MyPerson; // Null result means that there is no candidate with similarity score above threshold if (match == null) { //TEST CASE //MessageBox.Show("No matching person found."); return(false); } // Print out any non-null result //TEST CASE //MessageBox.Show(String.Format("Probe {0} matches registered person {1}", probe.Name, match.Name)); // Compute similarity score float score = Afis.Verify(probe, match); //TEST CASE //MessageBox.Show(String.Format("Similarity score between {0} and {1} = {2}", probe.Name, match.Name, score)); return(true); }
public static Fingerprint ExtraerTemplate(string huellaBase64) { AfisEngine Afis = new AfisEngine(); Fingerprint Huella = new Fingerprint(); Huella.AsBitmap = new Bitmap(Base64StringToBitmap(huellaBase64)); Person person = new Person(); person.Fingerprints.Add(Huella); Afis.Extract(person); return(new Fingerprint { Template = person.Fingerprints[0].Template }); }
static void Main(string[] args) { Afis = new AfisEngine(); List <MyPerson> database = new List <MyPerson>(); List <byte[]> ListOfImages = new List <byte[]>(); string pathString = string.Empty; byte[] byteArray; int ideal_value = 0; pathString = System.IO.Path.Combine(ImagePath, "fingerprint_2_93.tif"); byteArray = System.IO.File.ReadAllBytes(pathString); database.Add(Enroll(Path.Combine(ImagePath, "fingerprint_2_93.tif"), byteArray)); pathString = System.IO.Path.Combine(ImagePath, "fingerprint_3_83.tif"); byteArray = System.IO.File.ReadAllBytes(pathString); database.Add(Enroll(Path.Combine(ImagePath, "fingerprint_3_83.tif"), byteArray)); pathString = System.IO.Path.Combine(ImagePath, "probe_2_125.tif"); byteArray = System.IO.File.ReadAllBytes(pathString); MyPerson probe = Enroll(Path.Combine(ImagePath, "probe_2_125.tif"), byteArray); Afis.Threshold = 10; MyPerson match = Afis.Identify(probe, database).FirstOrDefault() as MyPerson; if (match == null) { //return "No matching person found."; } float score = Afis.Verify(probe, match); string matched_user = match.Name; if (ideal_value <= 0) { ideal_value = 60; } if (score > ideal_value) { Console.WriteLine("Matched user: "******"Score: " + score); } else { Console.WriteLine("No Matched user"); Console.WriteLine("Score: " + score); } Console.ReadLine(); }
private Usuario verificaHuella(Fingerprint fingerPrint) { Usuario usuarioVerificado = null; using (var context = new db_Entidades()) { UsuarioAFIS usuarioABuscar = new UsuarioAFIS(); usuarioABuscar.Fingerprints.Add(fingerPrint); //Creamos Objeto AfisEngine el cual realiza la identificación de usuarios AfisEngine Afis = new AfisEngine(); // Marcamos límite para verificar una huella como encontrada Afis.Threshold = 50; Afis.Extract(usuarioABuscar); //Obtenemos los usuarios registrados en la base de datos var usuariosBBDD = context.Usuario.ToList(); //Lista de tipo UsuarioAFIS, los cuales rellenamos con plantillas de huellas dactilares e id de usuario de la base de datos List <UsuarioAFIS> listaUsuariosAFIS = new List <UsuarioAFIS>(); foreach (var usuario in usuariosBBDD) { Fingerprint fingerPrintAUX = new Fingerprint(); fingerPrintAUX.AsIsoTemplate = usuario.finger; UsuarioAFIS usuarioAFIS_AUX = new UsuarioAFIS(); usuarioAFIS_AUX.id = usuario.id; usuarioAFIS_AUX.Fingerprints.Add(fingerPrintAUX); listaUsuariosAFIS.Add(usuarioAFIS_AUX); } //Realiza la busqueda UsuarioAFIS usuarioEncontrado = Afis.Identify(usuarioABuscar, listaUsuariosAFIS).FirstOrDefault() as UsuarioAFIS; if (usuarioEncontrado == null) { Console.WriteLine("No se ha encontrado"); //cS.enviaCadena("NO IDENTIFICADO"); usuarioVerificado = null; } else { //Obtenemos la puntuación de los usuarios identificados float puntuacion = Afis.Verify(usuarioABuscar, usuarioEncontrado); usuarioVerificado = usuariosBBDD.Find(x => x.id == usuarioEncontrado.id); //cS.enviaCadena("IDENTIFICADO"); //cS.enviaCadena(usuarioCompleto.username); Console.WriteLine("Encontrado con: {0:F3}, Nombre: {1}", puntuacion, usuarioVerificado.username); } } return(usuarioVerificado); }
public string ExtractTemplate(byte[] bitmap) { AfisEngine Afis = new AfisEngine(); Stream bitmapStream = new MemoryStream(bitmap); Fingerprint fp = new Fingerprint(); fp.AsBitmap = new Bitmap(bitmapStream); Person p = new Person(); p.Fingerprints.Add(fp); Afis.Extract(p); return(fp.AsXmlTemplate.ToString()); }
public void Extract() { AfisEngine afis = new AfisEngine(); Fingerprint fp = new Fingerprint() { AsBitmap = Settings.SomeFingerprint }; Assert.IsNull(fp.Template); afis.Extract(new Person(fp)); Assert.IsNotNull(fp.Template); Assert.Catch(() => { afis.Extract(new Person(new Fingerprint())); }); afis.Extract(new Person()); Assert.Catch(() => { afis.Extract(null); }); }
public void AsIsoTemplate() { Fingerprint fp1 = new Fingerprint() { AsBitmap = Settings.SomeFingerprint }; Assert.IsNull(fp1.AsIsoTemplate); AfisEngine afis = new AfisEngine(); afis.Extract(new Person(fp1)); Assert.IsNotNull(fp1.AsIsoTemplate); Fingerprint fp2 = new Fingerprint() { AsIsoTemplate = fp1.AsIsoTemplate }; Assert.AreEqual(fp1.AsIsoTemplate, fp2.AsIsoTemplate); Assert.IsNotNull(fp2.Template); Assert.IsNull(fp2.Image); Person person1 = new Person(fp1); Person person2 = new Person(fp2); Person person3 = new Person(new Fingerprint() { AsBitmap = Settings.NonMatchingFingerprint }); afis.Extract(person3); afis.Threshold = 0; Assert.That(afis.Verify(person1, person2) > afis.Verify(person1, person3)); fp1.AsIsoTemplate = Settings.Template1_1; fp2.AsIsoTemplate = Settings.Template1_2; person3.Fingerprints[0].AsIsoTemplate = Settings.Template2_2; Assert.That(afis.Verify(person1, person2) > afis.Verify(person2, person3)); fp2.AsIsoTemplate = Settings.Template2_2; Assert.That(afis.Verify(person1, person2) < afis.Verify(person2, person3)); fp1.AsIsoTemplate = null; Assert.IsNull(fp1.AsIsoTemplate); Assert.Catch(() => { fp1.AsIsoTemplate = new byte[100]; }); Assert.Catch(() => { fp1.AsIsoTemplate = fp2.Template; }); }
static void Main(string[] args) { // Initialize SourceAFIS Afis = new AfisEngine(); // Enroll some people List <MyPerson> database = new List <MyPerson>(); database.Add(Enroll(Path.Combine(ImagePath, "candidate1.tif"), "Fred Flintstone")); database.Add(Enroll(Path.Combine(ImagePath, "candidate2.tif"), "Wilma Flintstone")); database.Add(Enroll(Path.Combine(ImagePath, "candidate3.tif"), "Barney Rubble")); // Save the database to disk and load it back, just to try out the serialization BinaryFormatter formatter = new BinaryFormatter(); Console.WriteLine("Saving database..."); using (Stream stream = File.Open("database.dat", FileMode.Create)) formatter.Serialize(stream, database); Console.WriteLine("Reloading database..."); using (FileStream stream = File.OpenRead("database.dat")) database = (List <MyPerson>)formatter.Deserialize(stream); // Enroll visitor with unknown identity MyPerson probe = Enroll(Path.Combine(ImagePath, "probe.tif"), "Visitor #12345"); // Look up the probe using Threshold = 10 Afis.Threshold = 10; Console.WriteLine("Identifying {0} in database of {1} persons...", probe.Name, database.Count); MyPerson match = Afis.Identify(probe, database).FirstOrDefault() as MyPerson; // Null result means that there is no candidate with similarity score above threshold if (match == null) { Console.WriteLine("No matching person found."); Console.ReadKey(); return; } // Print out any non-null result Console.WriteLine("Probe {0} matches registered person {1}", probe.Name, match.Name); // Compute similarity score float score = Afis.Verify(probe, match); Console.WriteLine("Similarity score between {0} and {1} = {2:F3}", probe.Name, match.Name, score); Console.ReadKey(); }
public string DoFingerPrint(Stream stream) { AfisEngine Afis = new AfisEngine(); var fs = new SourceAFIS.Simple.Fingerprint(); fs.AsBitmap = new System.Drawing.Bitmap(stream); var person = new Person(); person.Fingerprints.Add(fs); Afis.Extract(person); return(person.Fingerprints[0].AsXmlTemplate.ToString()); }
public void Identify() { AfisEngine afis = new AfisEngine(); Person person1 = new Person(new Fingerprint() { AsBitmap = Settings.SomeFingerprint }); afis.Extract(person1); Person person2 = new Person(new Fingerprint() { AsBitmap = Settings.MatchingFingerprint }); afis.Extract(person2); Person person3 = new Person(new Fingerprint() { AsBitmap = Settings.NonMatchingFingerprint }); afis.Extract(person3); CollectionAssert.AreEqual(afis.Identify(person1, new[] { person2, person3 }), new[] { person2 }); CollectionAssert.AreEqual(afis.Identify(person1, new[] { person3, person2 }), new[] { person2 }); CollectionAssert.AreEqual(afis.Identify(person1, new[] { person3 }), new Person[0]); CollectionAssert.AreEqual(afis.Identify(person1, new[] { person2, person3, person1 }), new[] { person1, person2 }); Person person4 = new Person(person2.Fingerprints[0], person3.Fingerprints[0]); CollectionAssert.AreEqual(afis.Identify(person1, new[] { person4 }), new[] { person4 }); var bigArray = Enumerable.Repeat(person3, 100).Concat(new[] { person2 }).Concat(Enumerable.Repeat(person3, 100)); CollectionAssert.AreEqual(afis.Identify(person1, bigArray), new[] { person2 }); CollectionAssert.AreEqual(afis.Identify(person1, new Person[] { }), new Person[0]); CollectionAssert.AreEqual(afis.Identify(person1, new[] { new Person() }), new Person[0]); CollectionAssert.AreEqual(afis.Identify(new Person(), new[] { person2, person3 }), new Person[0]); Assert.Catch(() => { afis.Identify(null, new[] { person2, person3 }); }); Assert.Catch(() => { afis.Identify(new Person(null), new[] { person2, person3 }); }); Assert.Catch(() => { afis.Identify(person1, null); }); Assert.Catch(() => { afis.Identify(person1, new[] { person2, null }); }); Assert.Catch(() => { afis.Identify(person1, new[] { person2, new Person(null) }); }); }
static void Main(string[] args) { try { AfisEngine afis = new AfisEngine(); Fingerprint fp = new Fingerprint(); fp.AsBitmapSource = new BitmapImage(new Uri(args[0], UriKind.RelativeOrAbsolute)); Person person = new Person(fp); afis.Extract(person); File.WriteAllBytes(args[1], fp.Template); WriteLog(args, "OK"); } catch (Exception) { WriteLog(args, "FAIL"); throw; } }
static void Main(string[] args) { try { Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture; AfisEngine afis = new AfisEngine(); Person probe = LoadTemplate(args[0]); Person candidate = LoadTemplate(args[1]); afis.Threshold = 0; float score = afis.Verify(probe, candidate); float similarity = FixScore(score); WriteLog(args, "OK", similarity); } catch (Exception) { WriteLog(args, "FAIL", 0); } }
public static void Finger() { // Initialize SourceAFIS Afis = new AfisEngine(); // Enroll some people List <MyPerson> database = new List <MyPerson>(); database.Add(Enroll(Path.Combine(ImagePath, "candidate1.tif"), "Ankit Balyan")); database.Add(Enroll(Path.Combine(ImagePath, "candidate2.tif"), "Gurleen Singh")); database.Add(Enroll(Path.Combine(ImagePath, "candidate3.tif"), "Kunal Kholia")); // Save the database to disk and load it back, just to try out the serialization BinaryFormatter formatter = new BinaryFormatter(); using (Stream stream = File.Open("database.dat", FileMode.Create)) formatter.Serialize(stream, database); //Reloading Database using (FileStream stream = File.OpenRead("database.dat")) database = (List <MyPerson>)formatter.Deserialize(stream); // Enroll visitor with unknown identity MyPerson probe = Enroll(Path.Combine(ImagePath, "probe.tif"), "Visitor #12345"); // Look up the probe using Threshold = 10 Afis.Threshold = 60; MessageBox.Show(String.Format("Identifying {0} in database of {1} persons...", probe.Name, database.Count)); MyPerson match = Afis.Identify(probe, database).FirstOrDefault() as MyPerson; // Null result means that there is no candidate with similarity score above threshold if (match == null) { MessageBox.Show("No matching person found."); return; } // Print out any non-null result MessageBox.Show(String.Format("Probe {0} matches registered person {1}", probe.Name, match.Name)); // Compute similarity score float score = Afis.Verify(probe, match); MessageBox.Show(String.Format("Similarity score between {0} and {1} = {2:F3}", probe.Name, probe.Name, score)); }
public void Dpi() { AfisEngine afis = new AfisEngine(); Person person1 = new Person(new Fingerprint() { AsBitmap = Settings.SomeFingerprint }); Person person2 = person1.Clone(); afis.Extract(person1); afis.Dpi = 750; afis.Extract(person2); Assert.AreNotEqual(person1.Fingerprints[0].Template, person2.Fingerprints[0].Template); Assert.That(afis.Verify(person1, person2) == 0); afis.Dpi = 230; afis.Dpi = 1000; Assert.Catch(() => { afis.Dpi = 90; }); Assert.Catch(() => { afis.Dpi = 10000; }); }