【问题标题】:Biometric finger scanner deserializing template from database C#生物识别指纹扫描仪从数据库 C# 中反序列化模板
【发布时间】:2014-11-14 02:17:16
【问题描述】:

大家好,我只是需要一些帮助。我想知道我的代码是否正确,如果不是,请指导。我有一个使用 DPFP .NET (C#) SDK 的数字个人生物特征模型 U.ar.U 4500 我能够将序列化模板保存到数据库 ms-sql,我想知道序列化的方式是否正确。如果正确,我如何反序列化并将数据与机器模板进行比较。这是我的代码。

          public void EnrollmentControl_OnEnroll(Object Control, int Finger, DPFP.Template       
              Template, ref DPFP.Gui.EventHandlerStatus Status) {
          if (Data.IsEventHandlerSucceeds) {
               byte[] by = new byte[0];
               foreach (DPFP.Template template in Data.Templates)
               {
                    if (template != null) 
               {
                  by = new byte[template.Bytes.Length];
                       template.Serialize(ref by);
                       string PP;
                       string CR;
              PP = iSQL.STORED_PROCEDURE_FNG_IMG; // <- Stored Procedure INSERT INTO Employee_Img
              CR = "AB-0001-R12";
              iEmp emp = new iEmp(PP);                          // <- Class that insert to MS SQL 
              int rt = emp.Insert_Finger(CR, template.Bytes);   // <- return 1 if Successfully 
              if (rt == 1) { iCon.success_mgs(1, "Successfully Inserted", iSQL.EMPLOYEE_REGISTRN); } //<- Popup message
              else { iCon.success_mgs(1, "Successfully Inserted", iSQL.EMPLOYEE_REGISTRN); } 
            }
         }
          Data.Templates[Finger - 1] = Template;            // store a finger template
          ExchangeData(true);                               // update other data
          ListEvents.Items.Insert(0, String.Format("OnEnroll: finger {0}", Finger));
     }else
        Status = DPFP.Gui.EventHandlerStatus.Failure;   // force a "failure" status
   }  

【问题讨论】:

    标签: c# serialization biometrics


    【解决方案1】:

    我遇到过这个问题,然后我已经通过以下步骤修复了它:

    示例: pgAdmin:

    表名:

    -tbl_fptable

    数据库字段:

    fp_id (int) fp_data(文本)

    将数据插入数据库;

        protected override void Process(DPFP.Sample Sample)
        {
            base.Process(Sample);
    
            // Process the sample and create a feature set for the enrollment purpose.
            DPFP.FeatureSet features = ExtractFeatures(Sample, DPFP.Processing.DataPurpose.Enrollment);
    
            // Check quality of the sample and add to enroller if it's good
            if (features != null) try
            {
                MakeReport("The fingerprint feature set was created.");
                Enroller.AddFeatures(features);     // Add feature set to template.
            }
            finally {
                UpdateStatus();
    
                    // Check if template has been created.
    
                    switch (Enroller.TemplateStatus)
                {
    
                    case DPFP.Processing.Enrollment.Status.Ready:
                            // report success and stop capturing
    
                        byte[] serializedTemplate = null;
                        string str_temp = null;
                        DateTime cur_date = DateTime.Now;
                        Enroller.Template.Serialize(ref serializedTemplate);
                        //Enroller.Template.Serialize(ref str_temp);
    
                            if (serializedTemplate != null)
                        {
                                string result = System.Text.Encoding.UTF8.GetString(serializedTemplate);
                                Console.Write(result);
    
                                try
                            {
                                    using (NpgsqlConnection conn = new NpgsqlConnection("Host=127.0.0.1;Port=5432;User Id=UserName;Password=*****;Database=finger_print_db;"))
                                    {
                                        conn.Open();
    
    
                                        NpgsqlCommand dbcmd = conn.CreateCommand();
                                        try
                                        {
                                            // Store TemplateSerialize as string data
    
                                            dbcmd.CommandText= "INSERT INTO tbl_fptable( fp_data ) VALUES ( @serializedTemplate )";
    dbcmd.Parameters.AddWithValue("@serializedTemplate ", serializedTemplate);                                                                                                   
                                            dbcmd.ExecuteNonQuery();
                                        }
                                        finally
                                        {
                                            conn.Close();
                                        }
                                    }
    
                                }
                            catch (Exception ex)
                            {
                                throw ex;
                            }
    
                        }
    
                        OnTemplate(Enroller.Template);
                        SetPrompt("Click Close, and then click Fingerprint Verification.");
                        Stop();
                        break;
    
                    case DPFP.Processing.Enrollment.Status.Failed:  // report failure and restart capturing
                        Enroller.Clear();
                        Stop();
                        UpdateStatus();
                        OnTemplate(null);
                        Start();
                        break;
                }
            }
        }
    

    从数据库中获取数据以进行验证

    protected override void Process(DPFP.Sample Sample)
        {
    
            base.Process(Sample);
    
            // Process the sample and create a feature set for the enrollment purpose.
            DPFP.FeatureSet features = ExtractFeatures(Sample, DPFP.Processing.DataPurpose.Verification);
    
            // Check quality of the sample and start verification if it's good
            // TODO: move to a separate task
            if (features != null)
            {
    
                try
                {
                    using (NpgsqlConnection conn = new NpgsqlConnection("Host=127.0.0.1;Port=5432;User Id=UserName;Password=*****;Database=finger_print_db;"))
                    {
                        conn.Open();
                        try
                        {
                            NpgsqlCommand cmd = new NpgsqlCommand("SELECT * FROM tbl_fptable ORDER BY enr_id DESC LIMIT 1", conn);
                            NpgsqlDataReader dr = cmd.ExecuteReader();
                            while ((dr.Read()))
                            {
    
                                long fpid = Convert.ToInt64(dr["id"]);
                                byte[] fpbyte = (byte[])dr["finger_data"];
                                Stream stream = new MemoryStream(fpbyte );
                                DPFP.Template tmpObj = new DPFP.Template(stream);
    
    
                                DPFP.Verification.Verification.Result result = new DPFP.Verification.Verification.Result();
                                // Compare the feature set with our template     
                                Verificator.Verify(features, tmpObj, ref result);
                                UpdateStatus(result.FARAchieved);
                                if (result.Verified)
                                    MakeReport("The fingerprint was VERIFIED.");
                                else
                                    MakeReport("The fingerprint was NOT VERIFIED.");
                            }
                        }
                        finally
                        {
                            conn.Close();
                        }
                    }
    
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
        }
    

    我希望这个例子可以解决这个卡住。

    【讨论】:

    • 实际上我几个月前已经解决了这个问题,但我真的很感谢你的回答:D 无论如何谢谢。
    【解决方案2】:
    public class VerificationForm : CaptureForm
    {
        public void Verify(DPFP.Template template)
        {
            Template = template;
    
            ShowDialog();
        }
    
        protected override void Init()
        {
            base.Init();
            base.Text = "Fingerprint Verification";
            Verificator = new DPFP.Verification.Verification();     // Create a fingerprint template verificator
            UpdateStatus(0);
        }
        bool found = false; string fname = "";
        protected override void Process(DPFP.Sample Sample)
        {
            base.Process(Sample);
    
            // Process the sample and create a feature set for the enrollment purpose.
            DPFP.FeatureSet features = ExtractFeatures(Sample, DPFP.Processing.DataPurpose.Verification);
    
            // Check quality of the sample and start verification if it's good
            // TODO: move to a separate task
            if (features != null)
            {
                // Compare the feature set with our template
                DPFP.Verification.Verification.Result result = new DPFP.Verification.Verification.Result();
    
                string[] flist = Directory.GetFiles("c:/finger");
                int mx = flist.Length;
                int cnt = 0;
                bool found = false;
    
                 DPFP.Template templates;
                while (cnt < mx && !found)
                {
                   // MessageBox.Show(flist[cnt]);
                    using (FileStream fs = File.OpenRead(flist[cnt]))
                    {
                         templates = new DPFP.Template(fs);
                        Verificator.Verify(features, templates, ref result);
                        UpdateStatus(result.FARAchieved);
                    }
                    if (result.Verified)
                    {
                        found = true;
                        FileInfo nfo = new FileInfo(flist[cnt]);
                        fname = nfo.Name;                        
                        break;
                    }
                    else
                    {
                        found = false;
                        cnt++;
                    }
                }
    
    
                    if (found)
                    {
                        MakeReport("The fingerprint was VERIFIED. "+fname);
                        MessageBox.Show("Verified!!");
    
    
    
                    }
                    else
                    {
                        MakeReport("The fingerprint was NOT VERIFIED.");
                        MessageBox.Show("Not Verified!!");
    
                    }
    
            }
        }
    
        private void UpdateStatus(int FAR)
        {
            // Show "False accept rate" value
            SetStatus(String.Format("False Accept Rate (FAR) = {0}", FAR));
        }
    
        private DPFP.Template Template;
        private DPFP.Verification.Verification Verificator;
        private void InitializeComponent()
        {
            this.SuspendLayout();
            // 
            // VerificationForm
            // 
            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
            this.ClientSize = new System.Drawing.Size(693, 373);
            this.Name = "VerificationForm";
            this.Load += new System.EventHandler(this.VerificationForm_Load);
            this.ResumeLayout(false);
            this.PerformLayout();
    
        }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2010-12-26
      • 1970-01-01
      • 2021-12-31
      • 2016-05-26
      • 1970-01-01
      • 2023-04-02
      • 1970-01-01
      相关资源
      最近更新 更多