Пример #1
0
 private void btnSaveTemplate_Click(object sender, EventArgs e)
 {
     if (saveTemplateDialog.ShowDialog() == DialogResult.OK)
     {
         var tmp = _subject.GetTemplateBuffer().ToArray();
         File.WriteAllBytes(saveTemplateDialog.FileName, _subject.GetTemplateBuffer().ToArray());
     }
 }
Пример #2
0
        internal bool SaveActiveUserFingerRecords(NFinger finger, NSubject fingerSubject, FingerDescription fingerDescription)
        {
            try
            {
                var buffArray = fingerSubject?.GetTemplateBuffer().ToArray();

                var fRecord = new FingerImageRecord
                {
                    FingerIndex       = GetFingerIndex(fingerDescription),
                    FingerDescription = fingerDescription,
                    FingerRecord      = finger?.Objects[0].Template,
                    FingerSubject     = fingerSubject,
                    FingerTemplate    = buffArray
                };

                if (finger != null)
                {
                    var wsq = finger.Image.Save(NImageFormat.Wsq);
                    fRecord.FingerImage = finger.Image.ToBitmap();
                    fRecord.FingerWsq   = wsq?.ToArray();
                    int fingersCount = 0;
                    var status       = CheckDuplicate(fRecord);
                    return(status);
                }
                return(false);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                return(false);
            }
        }
Пример #3
0
        //save template into directory
        public static void SaveTemplate(NSubject subject)
        {
            try
            {
                BdifStandard standard = BdifStandard.Unspecified;
                //ISO or ANSI template stadard can be set before extraction
                Console.WriteLine("{0} template extracted.", standard == BdifStandard.Iso ?
                                  "ISO" : standard == BdifStandard.Ansi ? "ANSI" : "Proprietary");
                Console.WriteLine("Template extracted");


                if (standard == BdifStandard.Iso)
                {   //create BDifStandard.ISO template
                    File.WriteAllBytes(Config.TemplateNameISO(), subject.GetTemplateBuffer(CbeffBiometricOrganizations.IsoIecJtc1SC37Biometrics,
                                                                                           CbeffBdbFormatIdentifiers.IsoIecJtc1SC37BiometricsFingerMinutiaeRecordFormat,
                                                                                           FMRecord.VersionIsoCurrent).ToArray());
                    Console.WriteLine("ISO template saved successfully");
                }
                else if (standard == BdifStandard.Ansi)
                {
                    //create BDifStandard.ANSI template
                    File.WriteAllBytes(Config.TemplateNameANSI(), subject.GetTemplateBuffer(CbeffBiometricOrganizations.IncitsTCM1Biometrics,
                                                                                            CbeffBdbFormatIdentifiers.IncitsTCM1BiometricsFingerMinutiaeU,
                                                                                            FMRecord.VersionAnsiCurrent).ToArray());
                    Console.WriteLine("ANSI template saved successfully");
                }
                else
                {
                    //create general template
                    File.WriteAllBytes(Config.TemplateNameGeneral(), subject.GetTemplateBuffer().ToArray());
                    Console.WriteLine("template saved successfully");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }
Пример #4
0
        private void SaveTemplateButtonClick(object sender, EventArgs e)
        {
            if (_template == null)
            {
                return;
            }
            saveFileDialog.Filter = @"Template files (*.dat)|*.dat";
            saveFileDialog.Title  = @"Save Template File";
            if (_oldTemplateFilename != string.Empty)
            {
                saveFileDialog.FileName = _oldTemplateFilename;
            }

            if (saveFileDialog.ShowDialog() != DialogResult.OK)
            {
                return;
            }
            _oldTemplateFilename = saveFileDialog.FileName;

            // save template to file
            File.WriteAllBytes(saveFileDialog.FileName, _subject.GetTemplateBuffer().ToArray());
        }
Пример #5
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);
    }
Пример #6
0
        private void OnCapturingComplete(IAsyncResult r)
        {
            if (InvokeRequired)
            {
                BeginInvoke(new AsyncCallback(OnCapturingComplete), r);
            }
            else
            {
                try
                {
                    var status = _biometricClient.EndCapture(r);

                    if (status == NBiometricStatus.Ok)
                    {
                        TemplateLoginForm = _subject.GetTemplateBuffer().ToArray();

                        _enumoperation = Modes.Initialization;
                        if (_subject.Faces.Count > 1)
                        {
                            TemplateLoginForm = null;
                            lblInfo.Text      = Resources.ManyFaces;
                            lblInfo.ForeColor = Color.Red;
                            CapturingOperationInit();
                            _subject.Faces[0].Image = null;
                            _biometricClient.BeginCapture(_subject, OnCapturingComplete, null);
                        }
                        else
                        {
                            CloseButtonCapSuccessConfig();
                            _enumoperation = Modes.Capturesuccess;
                        }
                    }
                    else
                    {
                        TemplateLoginForm = null;

                        lblInfo.Text      = Resources.RestartCapture + "\n" + status;
                        lblInfo.ForeColor = Color.Red;
                        CapturingOperationInit();
                        _enumoperation          = Modes.Initialization;
                        _subject.Faces[0].Image = null;
                        _biometricClient.BeginCapture(_subject, OnCapturingComplete, null);
                    }
                }
                catch (InvalidOperationException)
                {
                    CheckCamera();
                    CheckLicense();
                    CapturingOperationInit();
                    _enumoperation = Modes.Initialization;
                }
                catch (Exception)
                {
                    CheckCamera();
                    CheckLicense();
                    CapturingOperationInit();

                    _enumoperation = Modes.Initialization;
                }
            }
        }
Пример #7
0
 private bool IsSubjectValid(NSubject subject)
 {
     return(subject != null && (subject.Status == NBiometricStatus.Ok ||
                                subject.Status == NBiometricStatus.None && subject.GetTemplateBuffer() != null));
 }
Пример #8
0
        private void OnCapturingCompleted(IAsyncResult r)
        {
            if (InvokeRequired)
            {
                BeginInvoke(new AsyncCallback(OnCapturingCompleted), r);
            }
            else
            {
                try
                {
                    var status = _biometricClient.EndCapture(r);
                    // If Stop button was pushed
                    if (status == NBiometricStatus.Canceled)
                    {
                        return;
                    }

                    lblStatus.Text = status.ToString();
                    if (status != NBiometricStatus.Ok)
                    {
                        // Since capture failed start capturing again
                        _subject.Faces[0].Image = null;
                        _biometricClient.BeginCapture(_subject, OnCapturingCompleted, null);
                    }
                    else
                    {
                        if (_subject.Faces[0].Image != null)
                        {
                            //facesView.Image = image;
                            var size = new Size {
                                Width = int.Parse(Settings.Default.ImageWidth), Height = int.Parse(Settings.Default.ImageHeight)
                            };
                            var memoryStream = new MemoryStream();
                            _subject.Faces[0].Image.ToBitmap().Save(memoryStream, System.Drawing.Imaging.ImageFormat.Jpeg);
                            var faceBoundingRect = _subject.Faces[0].Objects[0].BoundingRect;
                            //var resizedImage = _subject.Faces[0].Image.Crop(50, 50, 50, 50).ToBitmap();

                            //int widthOffset;
                            //if (faceBoundingRect.Left > faceBoundingRect.Right)
                            //{
                            //    //widthOffset = 2*tt.Right/6 + tt.Width;
                            //    widthOffset = (faceBoundingRect.Left - faceBoundingRect.Right) / 3 + faceBoundingRect.Width + 50;
                            //}
                            //else
                            //{
                            //    //widthOffset = 2*tt.Left/6 + tt.Width;
                            //    //widthOffset = tt.Left + tt.Width + 50;

                            //    widthOffset = (faceBoundingRect.Right - faceBoundingRect.Left) / 3 + faceBoundingRect.Width;
                            //}

                            //if (faceBoundingRect.Left > faceBoundingRect.Right)
                            //{
                            //    //widthOffset = tt.Left - tt.Right;
                            //    widthOffset = (faceBoundingRect.Right - faceBoundingRect.Right) / 2 + faceBoundingRect.Width / 2 + 50;
                            //}
                            //else
                            //{
                            //    widthOffset = faceBoundingRect.Right - faceBoundingRect.Left;
                            //    widthOffset = (faceBoundingRect.Width * 10) / 100 + faceBoundingRect.Width;
                            //}

                            var resizedImage = ResizeImage(memoryStream, (faceBoundingRect.Location.X - faceBoundingRect.Left) + faceBoundingRect.Width, faceBoundingRect.Height + 50, true, faceBoundingRect.X, faceBoundingRect.Top, faceBoundingRect.Right, faceBoundingRect.Bottom);
                            if (resizedImage != null)
                            {
                                pictureBoxCroped.Image = resizedImage;
                                _croppedPhotoImage     = resizedImage;
                            }
                            _template = _subject.GetTemplateBuffer();
                            EnableControls(false);
                        }

                        //UpdateView(_subject.Faces[0], status);
                    }
                }
                catch (Exception ex)
                {
                    AppUtils.ShowException(ex);
                    lblStatus.Text = string.Empty;
                    EnableControls(false);
                }
            }
        }