Exemplo n.º 1
0
        private int Identify(List <byte[]> capturedTemplateList, List <byte[]> enrolledTemplateList)
        {
            NMatcher matcher = new NMatcher();
            //List<MatchingResult> identifiedIDs = new List<MatchingResult>();
            NMatchingDetails details = null;

            matcher.Verify(enrolledTemplateList[0], capturedTemplateList[0], out details);

            return(details.FacesScore);
        }
Exemplo n.º 2
0
    /*
     * int score;
     * private void OnVerifyCompleted(IAsyncResult r)
     * {
     *  lock (locker)
     *  {
     *
     *      try
     *      {
     *          NBiometricStatus status = _biometricClient.EndVerify(r);
     *          if (status == NBiometricStatus.Ok || status == NBiometricStatus.MatchNotFound)
     *          {
     *              //get matching score
     *              score = _subject1.MatchingResults[0].Score;
     *              // string msg = string.Format("Score of matched templates: {0}", score);
     *              //msgLabel.Text = msg;
     *              // MessageBox.Show(msg);
     *          }
     *          else MessageBox.Show(status.ToString());
     *      }
     *      catch (Exception ex)
     *      {
     *          Utils.ShowException(ex);
     *      }
     *  }
     *
     * }*/
    protected void Button1_Click(object sender, EventArgs e)
    {
        deleteresultshow();
        NMatcher nm = new NMatcher();

        OpenImageTemplate(faceView1, out _subject1);
        MySqlConnection conn = new MySqlConnection("server=localhost;database=test;uid=root;password=root");

        conn.Open();
        String          sqlcommand = String.Format("select * from imgdata");
        MySqlCommand    cmd        = new MySqlCommand(sqlcommand, conn);
        MySqlDataReader msr        = cmd.ExecuteReader();

        while (msr.Read())
        {
            string   id                = (string)msr.GetValue(1);
            byte[]   blob              = (byte[])msr.GetValue(0);
            string   name              = (string)msr.GetValue(2);
            string   gender            = (string)msr.GetValue(3);
            DateTime bir               = (DateTime)msr.GetValue(4);
            string   birth             = bir.ToShortDateString();
            string   phonenumber       = (string)msr.GetValue(5);;
            Neurotec.Images.NImage img = ImageData.getNImageDataFromBytes(blob);
            NFace face = new NFace();
            face.Image = img;
            NSubject subject = new NSubject();
            subject.Faces.Add(face);
            //   _biometricClient.BeginCreateTemplate(subject, OnCreationCompleted, subject);
            nle.CreateTemplate(subject);
            //   Thread.Sleep(500);

            if (_subject1 != null && subject != null)
            {
                int score1 = nm.Verify(_subject1.GetTemplateBuffer(), subject.GetTemplateBuffer());
                //   _biometricClient.BeginVerify(_subject1,subject, OnVerifyCompleted, null);

                btlist.Add(new btnode(blob, score1, id, name, gender, birth, phonenumber));
            }
        }

        conn.Close();
        msr.Close();

        int    maxscore = 0;
        int    temp     = 0;
        string str      = "";

        for (int i = 0; i < btlist.Count; i++)
        {
            sqlcommand = "insert into resultshow(score,id,name,gender,birth,phonenumber,data) values(@score,@id,@name,@gender,@birth,@phonenumber,@data)";
            cmd        = new MySqlCommand(sqlcommand, conn);
            MySqlParameter[] param = new MySqlParameter[7];
            param[0] = new MySqlParameter("@score", btlist[i].score);
            param[1] = new MySqlParameter("@id", btlist[i].id);
            param[2] = new MySqlParameter("@name", btlist[i].name);
            param[3] = new MySqlParameter("@gender", btlist[i].gender);
            param[4] = new MySqlParameter("@birth", btlist[i].birth);
            param[5] = new MySqlParameter("@phonenumber", btlist[i].phonenumber);
            param[6] = new MySqlParameter("@data", btlist[i].blob);
            for (int j = 0; j < param.Length; j++)
            {
                cmd.Parameters.Add(param[j]);
            }
            conn.Open();
            try
            {
                cmd.ExecuteNonQuery();
            }
            catch (System.Exception ex)
            {
                StreamWriter sw = new StreamWriter("C:\\myerror.txt", true, Encoding.Default);
                sw.Write(ex.Message);
                sw.Close();
                //一旦发生错误程序就停止运行,等待用户发现
                Console.Read();
            }

            conn.Close();
            conn.Dispose();
            msr.Dispose();/*
                           * if (btlist[i].score>maxscore)
                           * {
                           * maxscore = btlist[i].score;
                           * temp = i;
                           * }*/
            //   str += btlist[i].score + "   ";
        }
        // MessageBox.Show(str);

        /*
         * sqlcommand = "insert into resultshow(score,data) values(@score,@data)";
         * cmd = new MySqlCommand(sqlcommand, conn);
         * MySqlParameter[] param = new MySqlParameter[2];
         * param[0] = new MySqlParameter("@score",btlist[temp].score);
         * param[1] = new MySqlParameter("@data", btlist[temp].blob);
         * for (int i = 0; i < param.Length; i++)
         *  cmd.Parameters.Add(param[i]);
         * conn.Open();
         * try
         * {
         *  cmd.ExecuteNonQuery();
         * }
         * catch (System.Exception ex)
         * {
         *  StreamWriter sw = new StreamWriter("C:\\myerror.txt", true, Encoding.Default);
         *  sw.Write(ex.Message);
         *  sw.Close();
         *  //一旦发生错误程序就停止运行,等待用户发现
         *  Console.Read();
         * }
         *
         * conn.Close();
         * conn.Dispose();
         * msr.Dispose();
         */
        Response.Redirect("Default4.aspx", false);
    }
Exemplo n.º 3
0
        private bool VerifyFingerprint(student originalStudent, NFRecord template2)
        {
            const string Components = "Biometrics.FingerExtraction,Biometrics.FingerMatching";
            bool matched = false;
            NFExtractor extractor = null;
            NMatcher matcher = null;
            try
            {
                // obtain license
                if (!NLicense.ObtainComponents("/local", 5000, Components))
                {
                    Console.WriteLine(@"Could not obtain licenses for components: {0}", Components);
                    matched = false;
                }

                // create an extractor
                extractor = new NFExtractor();

                // extract reference template
                NBuffer referenceTemplate = template2.Save();

                //For each finger in the NFRecord

                // extract candidate template
                NBuffer leftPinkie;
                NBuffer leftRing;
                NBuffer leftMiddle;
                NBuffer leftIndex;
                NBuffer leftThumb;
                NBuffer rightThumb;
                NBuffer rightIndex;
                NBuffer rightMiddle;
                NBuffer rightRing;
                NBuffer rightPinkie;
                int scoreLeftPinkie = 0;
                int scoreLeftRing = 0;
                int scoreLeftMiddle = 0;
                int scoreLeftIndex = 0;
                int scoreLeftThumb = 0;
                int scoreRightPinkie = 0;
                int scoreRightRing = 0;
                int scoreRightMiddle = 0;
                int scoreRightIndex = 0;
                int scoreRightThumb = 0;

                // create a matcher
                matcher = new NMatcher();
                if (originalStudent.LeftPinkie != null)
                {
                    leftPinkie = originalStudent.LeftPinkie.Save();
                    scoreLeftPinkie = matcher.Verify(referenceTemplate, leftPinkie);
                }

                if (originalStudent.LeftRing != null)
                {
                    leftRing = originalStudent.LeftRing.Save();
                    scoreLeftRing= matcher.Verify(referenceTemplate, leftRing);
                }

                if (originalStudent.LeftMiddle != null)
                {
                    leftMiddle = originalStudent.LeftMiddle.Save();
                    scoreLeftMiddle= matcher.Verify(referenceTemplate, leftMiddle);
                }
                if (originalStudent.LeftIndex != null)
                {
                    leftIndex = originalStudent.LeftIndex.Save();
                    scoreLeftIndex= matcher.Verify(referenceTemplate, leftIndex);
                }
                if (originalStudent.LeftThumb != null)
                {
                    leftThumb = originalStudent.LeftThumb.Save();
                    scoreLeftThumb = matcher.Verify(referenceTemplate, leftThumb);
                }
                if (originalStudent.RightThumb != null)
                {
                    rightThumb = originalStudent.RightThumb.Save();
                    scoreRightThumb = matcher.Verify(referenceTemplate, rightThumb);
                }

                if (originalStudent.RightIndex !=null)
                {
                    rightIndex = originalStudent.RightIndex.Save();
                    scoreRightIndex = matcher.Verify(referenceTemplate, rightIndex);
                }
                if (originalStudent.RightMiddle != null)
                {
                    rightMiddle = originalStudent.RightMiddle.Save();
                    scoreRightMiddle = matcher.Verify(referenceTemplate, rightMiddle);
                }
                if (originalStudent.RightRing != null)
                {
                    rightRing = originalStudent.RightRing.Save();
                    scoreRightRing = matcher.Verify(referenceTemplate, rightRing);
                }
                if (originalStudent.RightPinkie != null)
                {
                    rightPinkie = originalStudent.RightPinkie.Save();
                    scoreRightPinkie = matcher.Verify(referenceTemplate, rightPinkie);
                }

                if (scoreLeftPinkie > 0)
                {
                    matched = true;
                    matchedFingerID = 1;
                }
                if (scoreLeftRing > 0)
                {
                    matched = true;
                    matchedFingerID = 2;
                }

                if (scoreLeftMiddle > 0)
                {
                    matched = true;
                    matchedFingerID = 3;
                }
                if (scoreLeftIndex > 0)
                {
                    matched = true;
                    matchedFingerID = 4;
                }
                if (scoreLeftThumb > 0)
                {
                    matched = true;
                    matchedFingerID = 5;
                }
                if (scoreRightPinkie > 0)
                {
                    matched = true;
                    matchedFingerID = 6;
                }
                if (scoreRightRing > 0)
                {
                    matched = true;
                    matchedFingerID = 7;
                }
                if (scoreRightMiddle > 0)
                {
                    matched = true;
                    matchedFingerID = 8;
                }
                if (scoreRightIndex > 0)
                {
                    matched = true;
                    matchedFingerID = 9;
                }
                if (scoreRightThumb > 0)
                {
                    matched = true;
                    matchedFingerID = 10;
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
                //INeurotecException neurotecException = ex as INeurotecException;
                //if (neurotecException != null)
                //{
                //    return neurotecException.Code;
                //}
                matched = false;
            }
            finally
            {
                NLicense.ReleaseComponents(Components);

                if (extractor != null)
                {
                    extractor.Dispose();
                }
                if (matcher != null)
                {
                    matcher.Dispose();
                }

            }
            return matched;
        }
Exemplo n.º 4
0
        private string MatchStudents(NFRecord template, BindingList<student> StudentsInCourse)
        {
            const string Components = "Biometrics.FingerExtraction,Biometrics.FingerMatching";

            matchedFingerID = 0;
            matchedScore = 0;
            string highestStudent = "";
            int highestMatch = 0;

            NFExtractor extractor = null;
            NMatcher matcher = null;
            try
            {
                lblStatus.Text = "Getting License!";
                Application.DoEvents();
                // Obtain license.
                if (!NLicense.ObtainComponents(licServer, 5000, Components))
                {
                    Console.WriteLine(@"Could not obtain licenses for components: {0}", Components);
                    //return -1;
                }
                lblStatus.Text = "Got License!";
                Application.DoEvents();
                // create an extractor
                //extractor = new NFExtractor();

                // extract probe template

                NBuffer probeTemplate = template.Save();

                lblStatus.Text = "Exctracting templates";
                // extract gallery templates
                int args = StudentsInCourse.Count * 10;
                NBuffer[] galleryTemplates = new NBuffer[args - 1];
                string[] students = new string[args - 1];
                int n = 0;
                foreach (student currentStudent in StudentsInCourse)
                {
                    for (int count = 0; count < 10; count++)
                    {
                        try
                        {
                            galleryTemplates[n+count] = new NBuffer(currentStudent.template[count]);
                            students[n + count] = currentStudent.StudentNumber;

                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine("Could not load template for student" + currentStudent.StudentNumber + " - " + ex.Message);
                        }
                    }

                    n = n + 10;
                }

                // create a matcher
                matcher = new NMatcher();
                // identify reference template by comparing to each template from arguments
                Console.WriteLine(@"=== identification started ===");
                matcher.IdentifyStart(probeTemplate);

                lblStatus.Text = "Identifying start";
                try
                {
                    for (int i = 1; i < args; i++)
                    {
                        if (galleryTemplates[i - 1].Size != 0)
                        {
                            int score = matcher.IdentifyNext(galleryTemplates[i - 1]);
                            if (score > highestMatch)
                            {
                                Console.WriteLine(@"template[{0}] scored {1} {2}", i - 1, score, score > 0 ? "(Matched)" : "");
                                Console.WriteLine("student number matched: " + students[i-1]);
                                highestMatch = score;
                                highestStudent = students[i - 1];
                                matchedFingerID = i % 10;
                                matchedScore = score;
                            }

                        }

                    }
                }
                finally
                {
                    matcher.IdentifyEnd();
                }
                Console.WriteLine(@"=== identification finished ===");

                //return 0;
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);

            }
            finally
            {
                lblStatus.Text = "Releasing License";
                Application.DoEvents();
                NLicense.ReleaseComponents(Components);

                if (extractor != null)
                {
                    extractor.Dispose();
                }
                if (matcher != null)
                {
                    matcher.Dispose();
                }
                lblStatus.Text = "License Released";
                Application.DoEvents();
            }

            return highestStudent;
        }
Exemplo n.º 5
0
        private int Identify(List<byte[]> capturedTemplateList, List<byte[]> enrolledTemplateList)
        {
            NMatcher matcher = new NMatcher();
            //List<MatchingResult> identifiedIDs = new List<MatchingResult>();
            NMatchingDetails details = null;

            matcher.Verify(enrolledTemplateList[0], capturedTemplateList[0], out details);

            return details.FacesScore;
        }
Exemplo n.º 6
0
        private int Identify(List<byte[]> capturedTemplateList, List<byte[]> enrolledTemplateList)
        {
            //if (InvokeRequired)
            //{
            //    BeginInvoke(new IdentifyDelegate(Identify), capturedImages, enrolledTemplateList);
            //    return 0;
            //}
            /*
            List<byte[]> faceBytesList;
            using (NGrayscaleImage gray = capturedImages[0].ToGrayscale())
            {
                NleDetectionDetails ddetails;
                NleExtractionStatus status;
                //NLExtractor extractor = Tools.Extractor;
                NLExtractor extractor = new NLExtractor();
                //_extractor.ExtractStart();

                //extractor.TemplateSize = NleTemplateSize.Large;

                try { _extractor.DetectAllFeaturePoints = Settings.Default.ExtractorDetectAllFeaturesNonLive; }
                catch { }
                NLTemplate template = _extractor.Extract(gray, out ddetails, out status);
                if (template != null)
                {
                    faceBytesList = new List<byte[]>();
                    faceBytesList.Add(template.Save());
                    template.Dispose();
                }
                else
                    return 0;
            }
            */
            //int score = 0;
            NMatcher matcher = new NMatcher();
            //List<MatchingResult> identifiedIDs = new List<MatchingResult>();
            NMatchingDetails details = null;

            matcher.Verify(enrolledTemplateList[0], capturedTemplateList[0], out details);

            return details.FacesScore;
            /*
            matcher.IdentifyStart(enrolledTemplateList[0], out details);
            try
            {
                score = matcher.IdentifyNext(capturedTemplateList[0], details);
            }
            finally
            {
                matcher.IdentifyEnd();
            }
            return score;
            */
        }
Exemplo n.º 7
0
        private int identify()
        {
            verifyLicense();
            bool         largeTemplate   = true;
            cryptography decrypt         = new cryptography();
            NMatcher     templateMatcher = null;
            int          maxKeyNum       = 0;
            int          primKey         = 0;

            try {
                NBuffer probeTemplateBuffer = null;
                byte [] probeTemplateArray  = null;
                try {
                    NleDetectionDetails details;                     // unused
                    if (!createTemplate(globalInsetFaceBmp, largeTemplate, out details))
                    {
                        return(primKey);
                    }
                    probeTemplateBuffer = facialTemplate.Save();
                    probeTemplateArray  = probeTemplateBuffer.ToByteArray();
                } catch (IOException ex) {
                    MessageBox.Show("error reading input file {0}: " + ex);
                    return(primKey);
                }

                // extract gallery templates
                // This code allows for searching a database where rows (users) have been deleted,
                // causing primaryKeys to not be sequential.
                int row = 1;
                maxKeyNum = myDdInterface.maxPrimaryKey();
                if (maxKeyNum == 0)
                {
                    MessageBox.Show("There are no registered users.\nPlease enroll and try again.");
                    return(maxKeyNum);
                }
                List <byte []>  dbaseTemplates = new List <byte []> ();
                List <int [, ]> rowKeyList     = new List <int [, ]> ();        // list of row/primary keys

                for (int i = 0; i < maxKeyNum; i++)
                {
                    try {
                        byte [] tempArray = myDdInterface.getTemplateFromKey(i + 1);
                        if (tempArray != null)                        // skip deleted records
                        {
                            int [,] rowKeyRef = new int [1, 2];
                            dbaseTemplates.Add(tempArray);
                            // store row/primary key reference
                            rowKeyRef [0, 0] = row;
                            rowKeyRef [0, 1] = i + 1;
                            rowKeyList.Add(rowKeyRef);
                            row++;
                        }
                    } catch (IOException ex) {
                        MessageBox.Show("error reading reference template " + i + ": " + ex);
                        return(primKey);
                    }
                }

                templateMatcher = new NMatcher();
                templateMatcher.IdentifyStart(probeTemplateArray);

                try {
                    int numOfTemplates = dbaseTemplates.Count();
                    int score          = 0;
                    int highScore      = 0;
                    for (int i = 0; i < numOfTemplates; i++)
                    {
                        score = templateMatcher.IdentifyNext(dbaseTemplates [i]);
                        if (score > highScore)
                        {
                            highScore = score;
                            // get primary key based on row number
                            int [,] tempRef = new int [1, 2];
                            tempRef         = rowKeyList [i];
                            primKey         = tempRef [0, 1];
                        }
                    }
                    if (primKey == 0)
                    {
                        MessageBox.Show("Sorry, Unable to Identify.\nTry again.");
                        return(primKey);
                    }
                    else
                    {
                        string fName     = myDdInterface.getFName(primKey);
                        string lName     = myDdInterface.getLName(primKey);
                        Bitmap storedBmp = myDdInterface.getImageFromId(myDdInterface.userIdFromKey(primKey));                          // Check for potential errors referencing Primary key.
                        if (enrolledImagePictureBox.InvokeRequired)
                        {
                            enrolledImagePictureBox.Invoke(new Action(() => enrolledImagePictureBox.Image = storedBmp));
                            enrolledImageNameLabel.Invoke(new Action(() => enrolledImageNameLabel.Text    = (fName + " " + lName)));
                        }
                        else
                        {
                            enrolledImagePictureBox.Image = storedBmp;
                            enrolledImageNameLabel.Text   = (fName + " " + lName);
                        }
                        if (!enrolledImagePictureBox.Visible)
                        {
                            enrolledPicVisToggle();
                        }
                        if (tabIndex == 0)                        // play video only on main tab
                        {
                            playVideoFile(primKey);
                        }
                        return(primKey);
                    }
                } catch (Exception ex) {
                    MessageBox.Show("" + ex);
                } finally {
                    templateMatcher.IdentifyEnd();
                    facialTemplate = null;
                }
                return(primKey);
            } catch (Exception ex) {
                MessageBox.Show("" + ex);
                return(primKey);
            } finally {
                NLicense.ReleaseComponents(Components);
                if (templateMatcher != null)
                {
                    templateMatcher.Dispose();
                }
            }
        }