C# 生物特征指纹扫描仪从数据库C反序列化模板#
大家好,我只是需要一些帮助。我想知道我的代码是否正确,如果不正确,请指导。我有一个使用DPFP.NET(C#)SDK的数字个人生物特征模型U.ar.U 4500。我能够将序列化模板保存到数据库ms sql,我想知道序列化的方式是否正确。如果正确,如何反序列化数据并将其与机器模板进行比较。这是我的密码C# 生物特征指纹扫描仪从数据库C反序列化模板#,c#,serialization,biometrics,C#,Serialization,Biometrics,大家好,我只是需要一些帮助。我想知道我的代码是否正确,如果不正确,请指导。我有一个使用DPFP.NET(C#)SDK的数字个人生物特征模型U.ar.U 4500。我能够将序列化模板保存到数据库ms sql,我想知道序列化的方式是否正确。如果正确,如何反序列化数据并将其与机器模板进行比较。这是我的密码 public void EnrollmentControl_OnEnroll(Object Control, int Finger, DPFP.Template
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
}
public void registrmentcontrol\u oneroll(对象控件、int Finger、DPFP.Template
模板,参考DPFP.Gui.EventHandlerStatus){
如果(数据为IsEventHandlerSucceeds){
byte[]by=新字节[0];
foreach(Data.Templates中的DPFP.Template模板)
{
如果(模板!=null)
{
by=新字节[template.Bytes.Length];
模板。序列化(参照);
字符串PP;
字符串CR;
PP=iSQL.storage\u PROCEDURE\u FNG\u IMG;//我曾经遇到过这个问题,然后我已经通过以下步骤修复了它:
示例:
pgAdmin:
表名:
-tbl_表
DB字段:
fp_id(int)
fp_数据(文本)
将数据插入数据库;
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);
}
}
}
我希望这个例子可以解决这个问题。公共类验证表单:CaptureForm
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();
}
{
公共无效验证(DPFP.Template)
{
模板=模板;
ShowDialog();
}
受保护的重写void Init()
{
base.Init();
base.Text=“指纹验证”;
Verificator=new DPFP.Verification.Verification();//创建指纹模板验证器
更新状态(0);
}
bool found=false;字符串fname=“”;
受保护的覆盖无效进程(DPFP.Sample)
{
基础工艺(样品);
//处理样本并为注册目的创建功能集。
DPFP.FeatureSet features=ExtractFeatures(示例,DPFP.Processing.DataPurpose.Verification);
//检查样品的质量,如果质量好就开始验证
//TODO:移动到单独的任务
如果(功能!=null)
{
//将功能集与我们的模板进行比较
DPFP.Verification.Verification.Result结果=新的DPFP.Verification.Verification.Result();
字符串[]flist=Directory.GetFiles(“c:/finger”);
int mx=文件长度;
int-cnt=0;
bool-found=false;
模板;
而(cnt
Actual几个月前我已经解决了这个问题,但我非常感谢您的回答:D无论如何,谢谢。