예제 #1
0
        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); });
        }
예제 #2
0
        // Compares all subjects' fingerprints to a single image at a time
        static public string cmp(string dir)
        {
            string output = "";

            char[]             delim       = { '/', '\\' };
            char[]             delim_      = { '_', ',' };
            string[]           files       = Directory.GetFiles(dir, "*");
            List <Person>      persons     = new List <Person>();
            List <Fingerprint> fingers     = new List <Fingerprint>();
            List <string>      image_order = new List <string>();

            for (int i = 1; i < files.Length / 8 + 1; ++i)
            {
                Person p = new Person();
                p.Id = i;
                persons.Add(p);
            }
            Console.WriteLine("\tReading images...");
            foreach (string file in files)
            {
                string image = file.Split(delim)[file.Split(delim).Length - 1];
                int    index = -1;
                int.TryParse(image.Split(delim_)[0], out index);
                int finger_position = 0;
                int.TryParse(image.Split(delim_)[1], out finger_position);
                Fingerprint fp = new Fingerprint();
                fp.Finger = (Finger)finger_position;
                image_order.Add(image);
                fp.AsBitmapSource = new BitmapImage(new Uri(file, UriKind.RelativeOrAbsolute));
                persons[index - 1].Fingerprints.Add(fp);
                fingers.Add(fp);
            }
            int counter = 0;

            Console.WriteLine("\tExtracting persons...");
            Parallel.ForEach(persons, (p) => { engine.Extract(p); Console.WriteLine(++counter); });
            counter = 0;
            int total = persons.Count * fingers.Count;

            Console.WriteLine("\tVerifing comparisons...");
            Parallel.For(0, fingers.Count, (f) => {
                Person c = new Person();
                c.Fingerprints.Add(fingers[f]);
                engine.Extract(c);
                foreach (Person p in persons)
                {
                    float score = engine.Verify(p, c);
                    output     += p.Id.ToString() + "," + image_order[f] + "," + score + "\n";
                    Console.WriteLine(++counter + "\t/ " + total);
                }
            });
            return(output);
        }
예제 #3
0
        /// <summary>
        /// Handler for when a fingerprint is captured.
        /// </summary>
        /// <param name="captureResult">contains info and data on the fingerprint capture</param>
        private void OnCaptured(CaptureResult captureResult)
        {
            try
            {
                // Check capture quality and throw an error if bad.
                if (!_sender.CheckCaptureResult(captureResult))
                {
                    return;
                }

                SendMessage(Action.SendMessage, "A finger was captured.");
                Fingerprint newFingerPrint = new Fingerprint();
                if (count < 4)
                {
                    foreach (Fid.Fiv fiv in captureResult.Data.Views)
                    {
                        newFingerPrint.AsBitmap = _sender.CreateBitmap(fiv.RawImage, fiv.Width, fiv.Height);
                    }
                    patient.Fingerprints.Add(newFingerPrint);
                    Afis.Extract(patient);
                    count += 1;
                    if (count != 4)
                    {
                        SendMessage(Action.SendMessage, "Now place your next finger on the reader.");
                    }
                    else
                    {
                        SendMessage(Action.SendMessage, "Now place a search finger on the reader.");
                    }
                }
                else if (count > 0)
                {
                    Person matchFinger = new Person();

                    foreach (Fid.Fiv fiv in captureResult.Data.Views)
                    {
                        newFingerPrint.AsBitmap = _sender.CreateBitmap(fiv.RawImage, fiv.Width, fiv.Height);
                    }
                    matchFinger.Fingerprints.Add(newFingerPrint);
                    Afis.Extract(matchFinger);
                    long   memUsage    = GetMemoryUsage(patient);
                    float  score       = Afis.Verify(matchFinger, patient);
                    bool   match       = (score > Afis.Threshold);
                    string matchString = "AFIS doesn't match.  Get out of here kid!";
                    if (match)
                    {
                        matchString = "AFIS matches.";
                    }

                    SendMessage(Action.SendMessage, "Identification resulted: " + matchString + " score = " + score.ToString());
                    SendMessage(Action.SendMessage, "Place another finger on the reader.");
                    count += 1;
                }
            }
            catch (Exception ex)
            {
                // Send error message, then close form
                SendMessage(Action.SendMessage, "Error:  " + ex.Message);
            }
        }
예제 #4
0
        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();
        }
예제 #5
0
        public MyPerson recognition(MyPerson probeUser)
        {
            MyPerson matchUser = null;

            try
            {
                //matchUser = UserManager.afis.Identify(probeUser, loadUsers()).FirstOrDefault() as MyPerson;

                matchUser = (from candidate in loadUsers()
                             let score = afis.Verify(probeUser, candidate)
                                         where score >= afis.Threshold
                                         orderby score descending
                                         select candidate).FirstOrDefault();
                if (matchUser == null)
                {
                    Console.WriteLine("No matching person found.");
                    Console.Out.WriteLine();
                    return(matchUser);
                }
                // Print out any non-null result
                //Console.WriteLine("Probe {0} matches registered person {1}", probeUser.Name, matchUser.Name);

                // Compute similarity score
                //float scorea = UserManager.afis.Verify(probeUser, matchUser);
                //Console.WriteLine("Similarity score between {0} and {1} = {2:F3}", probeUser.Name, matchUser.Name, scorea);
                Console.Out.WriteLine();
                return(matchUser);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                Console.Out.WriteLine();
            }
            return(matchUser);
        }
        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);
        }
예제 #7
0
파일: Program.cs 프로젝트: jerem/afis
        }//Enroll

        //Match probe with people in the database
        public static Match getMatch(string fpPath, string visitorId, Int32 threshold)
        {
            Match match = new Match();

            // Match visitor with unknown identity
            MyPerson probe = getProbe(fpPath, visitorId);

            if (persons == null)
            {
                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
예제 #8
0
        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>");
        }
예제 #9
0
        public void Template()
        {
            Fingerprint fp1 = new Fingerprint()
            {
                AsBitmap = Settings.SomeFingerprint
            };

            Assert.IsNull(fp1.Template);

            AfisEngine afis = new AfisEngine();

            afis.Extract(new Person(fp1));
            Assert.IsNotNull(fp1.Template);

            byte[] saved = fp1.Template;
            Assert.AreNotSame(fp1.Template, saved);
            Assert.AreEqual(fp1.Template, saved);

            Fingerprint fp2 = new Fingerprint()
            {
                Template = fp1.Template
            };

            Assert.AreEqual(fp1.Template, 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));
            Assert.AreEqual(afis.Verify(person1, person3), afis.Verify(person2, person3));

            fp1.Template = null;
            Assert.IsNull(fp1.Template);

            Assert.Catch(() => { fp1.Template = new byte[100]; });
            Assert.Catch(() => { fp1.Template = fp2.AsIsoTemplate; });
        }
예제 #10
0
        /// <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));
        }
예제 #11
0
        void StartCore()
        {
            tts.Speak("叮咚", QueueMode.Flush, null);
            if (isIdentify && System.IO.File.Exists(ImagePath + nowLesson + ".dat"))                 //指纹识别
            // Enroll visitor with unknown identity
            //MyPerson probe = Enroll(ImagePath + "t1.BMP", "##Visitor##");
            {
                tv.Text = "开始识别。。。";
                MyPerson probe = Enroll(pics, "##Visitor##");
                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.");
                    result.Text = "无匹配指纹!";
                    tts.Speak("不认识你", QueueMode.Flush, null);
                }
                else
                {
                    // 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);
                    tv.Text = "识别完成。。。";
                    tts.Speak(match.Name, QueueMode.Flush, null);
                    judgeTime(match.Name);
                    result.Text = "身份:" + match.Name + "\n匹配分数:" + score;
                }
            }
            else if (xuehao != null)                 //指纹录入
            //database.Add(Enroll(ImagePath + "r1.BMP", xuehao));
            {
                database.Add(Enroll(pics, xuehao));
                xuehao = null;

                // Save the database to disk and load it back, just to try out the serialization
                Console.WriteLine("Saving database...");
                BinaryFormatter formatter = new BinaryFormatter();
                using (Stream stream = File.Open(ImagePath + nowLesson + ".dat", FileMode.OpenOrCreate))
                    formatter.Serialize(stream, database);

                isIdentify = true;
                tv.Text    = "指纹已录入,开始识别。。。";
            }
            else
            {
                //Toast.MakeText(Application.Context,"请先录入指纹",ToastLength.Short).Show();
            }
        }
예제 #12
0
        public void AsXmlTemplate()
        {
            Fingerprint fp1 = new Fingerprint()
            {
                AsBitmap = Settings.SomeFingerprint
            };

            Assert.IsNull(fp1.AsXmlTemplate);

            AfisEngine afis = new AfisEngine();

            afis.Extract(new Person(fp1));
            Assert.IsNotNull(fp1.AsXmlTemplate);

            Fingerprint fp2 = new Fingerprint()
            {
                AsXmlTemplate = fp1.AsXmlTemplate
            };

            Assert.AreEqual(fp1.AsXmlTemplate.ToString(), fp2.AsXmlTemplate.ToString());
            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.AsXmlTemplate = null;
            Assert.IsNull(fp1.AsXmlTemplate);
            Assert.IsNull(fp1.Template);

            Assert.Catch(() => { fp1.AsXmlTemplate = new XElement("garbage"); });
        }
예제 #13
0
        public void Threshold()
        {
            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);

            float score = afis.Verify(person1, person2);

            Assert.That(score > 0);

            afis.Threshold = 1.001f * score;
            Assert.That(afis.Verify(person1, person2) == 0);
            Assert.That(afis.Identify(person1, new[] { person2 }).Count() == 0);

            afis.Threshold = 0.999f * score;
            Assert.That(afis.Verify(person1, person2) > 0);
            Assert.That(afis.Identify(person1, new[] { person2 }).Count() > 0);

            afis.Threshold = score;
            Assert.That(afis.Verify(person1, person2) > 0);
            Assert.That(afis.Identify(person1, new[] { person2 }).Count() > 0);

            afis.Threshold = 0;
            Assert.That(afis.Verify(person1, person2) > 0);
            Assert.That(afis.Identify(person1, new[] { person2 }).Count() > 0);

            Assert.Catch(() => { afis.Threshold = -0.001f; });
        }
예제 #14
0
        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);
        }
예제 #15
0
        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();
        }
예제 #16
0
        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);
        }
예제 #17
0
        private float Match(Person probe, Person candidate, float threshold)
        {
            try
            {
                _afisEngine.Threshold = threshold;

                var matchScore = _afisEngine.Verify(probe, candidate);

                return(matchScore);
            }
            catch (Exception ex)
            {
                throw new Exception(CannotMatchError, ex);
            }
        }
        // Ok
        /// <summary>
        /// zoek voor van wie de vingerprint is
        /// </summary>
        /// <param name="allPersons">list of persons ( with fingerprinttemplate and id )</param>
        /// <param name="inFingerprintTemplate">fingerprint template</param>
        /// <returns></returns>
        public static int idOfPersonThatLooksLike(List <Person> allPersons, byte[] inFingerprintTemplate)
        {
            Person      personToId         = new Person();
            Fingerprint unknownFingerprint = new Fingerprint();

            unknownFingerprint.Template = inFingerprintTemplate;
            personToId.Fingerprints.Add(unknownFingerprint);
            foreach (Person person in allPersons)
            {
                float resValue = Afis.Verify(person, personToId);
                if (resValue >= 0)
                {
                    return(person.Id);
                }
            }
            return(-420);
        }
        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();
        }
예제 #20
0
 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);
     }
 }
예제 #21
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));
        }
예제 #22
0
        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; });
        }
예제 #23
0
파일: Form1.cs 프로젝트: isiser/ZavrsniRad
        private void btnProvjeraPrsta_Click(object sender, EventArgs e)
        {
            List <Otisak_prsta> listaOtisaka = new List <Otisak_prsta>();

            listaOtisaka = Otisak_prsta.DohvatiOtiske();
            foreach (var item in listaOtisaka)
            {
                Fingerprint fp = new Fingerprint();
                fp.AsBitmap = new Bitmap(Bitmap.FromFile(Application.StartupPath + item.Otisak_putanja));
                Person osoba = new Person();
                osoba.Id = item.FK_korisnik;
                osoba.Fingerprints.Add(fp);
                Afis.Extract(osoba);
                ListaOsobaIzBaze.Add(osoba);
            }

            Afis.Threshold = 40;
            Person matchingCandidate = Afis.Identify(NepoznataOsoba, ListaOsobaIzBaze).FirstOrDefault();

            if (matchingCandidate == null)
            {
                MessageBox.Show("Nije pronadena osoba s navedenim otiskom prsta!");
            }
            else
            {
                Korisnik trazeniKorisnik = new Korisnik();
                trazeniKorisnik = Korisnik.DohvatiKorisnika(matchingCandidate.Id);
                float score = Afis.Verify(NepoznataOsoba, matchingCandidate);
                bool  match = (score > 0);
                MessageBox.Show("Pronađen je korisnik: " + trazeniKorisnik.Korisnicko_ime + " s koeficijentom podudranja: " + score.ToString());
                if (trazeniKorisnik.Korisnicko_ime == textBoxKorIme.Text)
                {
                    zastavicaPrst              = true;
                    lblOsobaFinger.Text        = trazeniKorisnik.Korisnicko_ime;
                    lblOsobaFinger.ForeColor   = System.Drawing.Color.Green;
                    lblFingerTocnost.Text      = score.ToString();
                    lblFingerTocnost.ForeColor = System.Drawing.Color.Green;
                }
            }
            ProvjeraPrijave();
        }
예제 #24
0
        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            byte[] imageBytes = Convert.FromBase64String(img_val.Value);

            fp.AsBitmap = CreateBmpImage(imageBytes);
            probe.Fingerprints.Add(fp);
            afis.Extract(probe);
            Person matchingCandidate = afis.Identify(probe, users).FirstOrDefault() as Person;
            bool   match             = (matchingCandidate != null);

            if (match == true)
            {
                float score = afis.Verify(probe, matchingCandidate);
                //Response.Write("<br><br>Score=" + score.ToString() + "<br><br>ID=" + matchingCandidate.Id.ToString());
                CheckAccountStatus(matchingCandidate.Id);
            }
            else
            {
                Response.Write("No user Found");
            }
        }
예제 #25
0
        static void buildDB(int TotalFiles, string path, string[] files, string[] share)
        {
            AfisEngine Afis = new AfisEngine();

            Afis.Threshold = 5;

            Fingerprint fp1 = new Fingerprint();
            Fingerprint fp2 = new Fingerprint();

            int k = 0;

            for (int i = 0; i < files.Length; i++)
            {
                fp1.AsBitmapSource = new BitmapImage(new Uri(files[i], UriKind.RelativeOrAbsolute));
                Person person1 = new Person();
                person1.Fingerprints.Add(fp1);
                Afis.Extract(person1);

                for (int j = 0; j < share.Length; j++)
                {
                    fp2.AsBitmapSource = new BitmapImage(new Uri(share[j], UriKind.RelativeOrAbsolute));
                    Person person2 = new Person();
                    person2.Fingerprints.Add(fp2);

                    Afis.Extract(person2);

                    float score = Afis.Verify(person1, person2);
                    bool  match = (score > Afis.Threshold);
                    Console.WriteLine(files[i] + "\n Compare with " + share[j]);
                    Console.WriteLine(score.ToString());
                    using (StreamWriter sw = File.AppendText(path))
                    {
                        sw.WriteLine(score.ToString());
                    }
                    k++;
                }
                Console.WriteLine("\n");
            }
        }
예제 #26
0
        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            byte[] imageBytes = Convert.FromBase64String(img_val.Value);

            fp.AsBitmap = CreateBmpImage(imageBytes);
            //fp.AsBitmap = new System.Drawing.Bitmap(System.Drawing.Bitmap.FromFile(Server.MapPath("~/admin/ThumbData/probe.bmp")));
            candidate.Fingerprints.Add(fp);
            sfis.Extract(candidate);
            int score = (int)Math.Ceiling(sfis.Verify(candidate, probe));

            Label1.Text = score.ToString();
            if (score > 0)
            {
                Session["id"]   = probe.Id.ToString();
                Session["type"] = 1;
                Response.Redirect("Dashboard.aspx");
            }
            else
            {
                Response.Redirect("Login.aspx?eid=3");
            }
        }
예제 #27
0
        static void Main(string[] args)
        {
            //var t = HexString2.Split().Select(s => Convert.ToByte(s, 16)).ToArray();
            var t = StringToByteArray(HexFromTemplate);

            var afisEngine  = new AfisEngine();
            var enrollPrint = new Fingerprint {
                AsIsoTemplate = t
            };
            var enrollPerson = new Person(enrollPrint);
            var verifyPrint  = new Fingerprint {
                AsIsoTemplate = t
            };
            var verifyPerson = new Person(verifyPrint);

            var matchScore = afisEngine.Verify(enrollPerson, verifyPerson);

            Console.WriteLine("Template length: {0}", enrollPrint.Template.Length);
            Console.WriteLine("Matching Score: {0}", matchScore);
            Console.WriteLine("Finished");
            Console.ReadLine();
        }
예제 #28
0
        public void Verify()
        {
            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);

            Assert.That(afis.Verify(person1, person2) > 0);
            Assert.That(afis.Verify(person1, person3) == 0);
            Assert.That(afis.Verify(person1, person1) > 0);

            Person person4 = new Person(person2.Fingerprints[0], person3.Fingerprints[0]);

            Assert.That(afis.Verify(person1, person4) > 0);

            Assert.That(afis.Verify(person1, new Person()) == 0);

            Assert.Catch(() => { afis.Verify(null, person1); });
            Assert.Catch(() => { afis.Verify(person1, null); });
            Assert.Catch(() => { afis.Verify(person1, new Person(null)); });
        }
예제 #29
0
        public async Task <ActionResult> Match([Bind(Include = "Name, Filename")] mortal mortal)
        {
            if (ModelState.IsValid & mortal.filename != null)
            {
                AfisEngine Afis = new AfisEngine();
                Afis.Threshold = 10;

                Fingerprint fp1 = new Fingerprint();
                Fingerprint fp2 = new Fingerprint();

                MyPerson person1 = new MyPerson();
                MyPerson person2 = new MyPerson();

                string apppath      = System.IO.Path.Combine(Server.MapPath("~"), "images");
                string pathToImage1 = (System.IO.Path.Combine(apppath, mortal.name));
                string pathToImage2 = (System.IO.Path.Combine(apppath, mortal.filename));


                Bitmap bitmap1 = fp1.AsBitmap = new Bitmap(Image.FromFile(pathToImage1));
                Bitmap bitmap2 = fp2.AsBitmap = new Bitmap(Image.FromFile(pathToImage2));


                person1.Fingerprints.Add(fp1);
                person2.Fingerprints.Add(fp2);
                Afis.Extract(person1);
                Afis.Extract(person2);
                float score = Afis.Verify(person1, person2);
                if (score > Afis.Threshold)
                {
                    Response.Write("<script>alert('" + score.ToString() + "');</script>");
                }
                return(View());
            }
            Response.Write("<script>alert('Please Enter Filename');</script>");
            return(View());
        }
예제 #30
0
        /// <summary>
        /// Handler for when a fingerprint is captured.
        /// </summary>
        /// <param name="captureResult">contains info and data on the fingerprint capture</param>
        private void OnCaptured(CaptureResult captureResult)
        {
            try
            {
                // Check capture quality and throw an error if bad.
                if (!_sender.CheckCaptureResult(captureResult))
                {
                    return;
                }

                SendMessage(Action.SendMessage, "A finger was captured.");

                //DataResult<Fmd> resultConversion = FeatureExtraction.CreateFmdFromFid(captureResult.Data, Constants.Formats.Fmd.ANSI);
                //if (resultConversion.ResultCode != Constants.ResultCode.DP_SUCCESS)
                //{
                //    _sender.Reset = true;
                //    throw new Exception(resultConversion.ResultCode.ToString());
                //}

                if (count == 0)
                {
                    //firstFinger = resultConversion.Data;
                    // Create bitmap
                    foreach (Fid.Fiv fiv in captureResult.Data.Views)
                    {
                        fp1.AsBitmap = _sender.CreateBitmap(fiv.RawImage, fiv.Width, fiv.Height);
                    }
                    person1.Fingerprints.Add(fp1);
                    Afis.Extract(person1);
                    //string serializedFinger = Fmd.SerializeXml(firstFinger);
                    count += 1;
                    SendMessage(Action.SendMessage, "Now place the same or a different finger on the reader.");
                }
                else if (count == 1)
                {
                    //secondFinger = resultConversion.Data;
                    foreach (Fid.Fiv fiv in captureResult.Data.Views)
                    {
                        fp2.AsBitmap = _sender.CreateBitmap(fiv.RawImage, fiv.Width, fiv.Height);
                    }
                    person2.Fingerprints.Add(fp2);

                    Afis.Extract(person2);
                    float  score       = Afis.Verify(person1, person2);
                    bool   match       = (score > 23);
                    string matchString = "AFIS doesn't match.  Get out of here kid!";
                    if (match)
                    {
                        matchString = "AFIS matches.";
                    }
                    //CompareResult compareResult = Comparison.Compare(firstFinger, 0, secondFinger, 0);
                    //string serializedFinger = Fmd.SerializeXml(secondFinger);
                    //if (compareResult.ResultCode != Constants.ResultCode.DP_SUCCESS)
                    //{
                    //    _sender.Reset = true;
                    //    throw new Exception(compareResult.ResultCode.ToString());
                    //}
                    SendMessage(Action.SendMessage, "SourceAFIS = " + matchString + " " + score.ToString());
                    //SendMessage(Action.SendMessage, "Comparison resulted in a dissimilarity score of " + compareResult.Score.ToString() + (compareResult.Score < (PROBABILITY_ONE / 100000) ? " (fingerprints matched)" : " (fingerprints did not match)"));
                    SendMessage(Action.SendMessage, "Place a finger on the reader.");
                    count = 0;
                }
            }
            catch (Exception ex)
            {
                // Send error message, then close form
                SendMessage(Action.SendMessage, "Error:  " + ex.Message);
            }
        }