来自数据库的 Digital Persona 指纹验证不起作用

Digital Persona Finger Print Verification from DataBase not working

   Device  :  Digital Persona u.are.u 4500 

注册时,我将数据以 image 格式保存在 sql 数据库中(sql 数据类型为图像)它工作正常 我的数据已正确保存在数据库中,但是现在,当我在验证过程中验证数据时,它给出了异常

hresult : 0xffff.

这是我的C#验证代码

SqlConnection conn = new SqlConnection(connetionstring);
conn.Open();
SqlCommand cmd = new SqlCommand("SELECT * FROM mySavedDataTable", conn);
MemoryStream ms;
byte[] fpBytes;
SqlDataAdapter sd = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
sd.Fill(dt);

foreach (DataRow dr in dt.Rows)
{
    fpBytes = Encoding.UTF8.GetBytes(dr["Template"].ToString());
    ms = new System.IO.MemoryStream(fpBytes);
    DPFP.Template template = new DPFP.Template();
    template.Serialize(ms);
    Verificator.Verify(features, template, ref result);
    if (result.Verified)
    {
        ver = true;
        break;
    }
}
conn.Close();

我这样做了,效果很好!

DataResult<Fmd> resultConversion = null;
IdentifyResult identifyResult = null;
string MobileNumber = "";
string Cnic = "";

// Check capture quality and throw an error if bad.
if (!this.CheckCaptureResult(captureResult)) return;
// See the SDK documentation for an explanation on threshold scores.
int thresholdScore = DPFJ_PROBABILITY_ONE * 1 / 100000;
DataSet dataSetBiometric = DatabaseHandler.getData("select CNIC, MOBILE_NUMBER, BIOMETRIC from ACCOUNT_OPENING");
//select CNIC, MOBILE_NUMBER, BIOMETRIC from ACCOUNT_OPENING
Fmd[] fmds = new Fmd[dataSetBiometric.Tables[0].Rows.Count];
for (int i = 0; i < dataSetBiometric.Tables[0].Rows.Count; i++)
{
    fmds[0] = Fmd.DeserializeXml(dataSetBiometric.Tables[0].Rows[i]["BIOMETRIC"].ToString());//BIOMETRIC
    resultConversion = FeatureExtraction.CreateFmdFromFid(captureResult.Data, Constants.Formats.Fmd.ANSI);
    identifyResult = Comparison.Identify(resultConversion.Data, 0, fmds, thresholdScore, dataSetBiometric.Tables[0].Rows.Count);
    if (identifyResult.ResultCode == Constants.ResultCode.DP_SUCCESS)
    {
        MobileNumber = dataSetBiometric.Tables[0].Rows[i]["MOBILE_NUMBER"].ToString();
        Cnic = dataSetBiometric.Tables[0].Rows[i]["CNIC"].ToString();
        break;
    }
}

我已经这样做了,希望对您有所帮助(完整的工作解决方案)Digital Persona onetouch sdk

Imports System.Reflection.MethodBase
Imports System.Data.SqlClient
Imports System.IO

Public Class frmThumbEnrol
    Implements DPFP.Capture.EventHandler

    Private Capturer As DPFP.Capture.Capture
    Delegate Sub FunctionCall(ByVal param)

    Private Event OnTemplate(ByVal template)

    Private Enroller As DPFP.Processing.Enrollment
    Public Sel_UsrID As String

    Public Enum Thumb
        Enrol
        Verify
    End Enum
    Public theModule As Thumb

    Private Sub Me_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Try
            If theModule = Thumb.Enrol Then
                Me.Text = "[ Thumb Impression - Enrol ]"
                Me.btnSave.Visible = True
                Me.btnClose.Text = "Cancel"
            Else
                Me.Text = "[ Thumb Impression - Verify ]"
                Me.btnSave.Visible = False
                Me.btnClose.Text = "Close"
            End If

            Me.txtStatus.Clear()
            Me.PBoxThumb.Image = Nothing
            Me.lblCount.Text = ""

            Init()

            StartCapture()

        Catch ex As Exception
            ErrMsg(ex, GetCurrentMethod.Name)
        End Try
    End Sub

    Public Overridable Sub Init()
        Try

            Capturer = New DPFP.Capture.Capture() 'create a capture operation.
            Enroller = New DPFP.Processing.Enrollment

            Me.lblCount.Text = IIf(theModule = Thumb.Enrol, "Fingerprint Samples Needed: " & Enroller.FeaturesNeeded.ToString, "")

            If (Not Capturer Is Nothing) Then
                Capturer.EventHandler = Me 'capturing events.
            Else
                MakeReport("Can't initiate capture operation!")
            End If

        Catch ex As Exception
            ErrMsg(ex, GetCurrentMethod.Name)
        End Try
    End Sub

    Private Sub StartCapture()
        Try

            If (Not Capturer Is Nothing) Then
                Capturer.StartCapture()
            End If

        Catch ex As Exception
            ErrMsg(ex, GetCurrentMethod.Name)
        End Try
    End Sub

    '------------------------------------------------------------------------------------------------------------------
    Private Sub btnClose_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClose.Click
        Try

            StopCapture()

            Me.Close()

        Catch ex As Exception
            ErrMsg(ex, GetCurrentMethod.Name)
        End Try
    End Sub

    Private Sub StopCapture()
        Try

            If (Not Capturer Is Nothing) Then
                Capturer.StopCapture()
            End If

        Catch ex As Exception
            ErrMsg(ex, GetCurrentMethod.Name)
        End Try
    End Sub

    '------------------------------------------------------------------------------------------------------------------
    Private Sub OnReaderConnect(ByVal Capture As Object, ByVal ReaderSerialNumber As String) Implements DPFP.Capture.EventHandler.OnReaderConnect
        Try

            MakeReport("The fingerprint reader was connected.")

        Catch ex As Exception
            ErrMsg(ex, GetCurrentMethod.Name)
        End Try
    End Sub
    Private Sub OnReaderDisconnect(ByVal Capture As Object, ByVal ReaderSerialNumber As String) Implements DPFP.Capture.EventHandler.OnReaderDisconnect
        Try

            MakeReport("The fingerprint reader was disconnected.")

        Catch ex As Exception
            ErrMsg(ex, GetCurrentMethod.Name)
        End Try
    End Sub

    Private Sub OnFingerTouch(ByVal Capture As Object, ByVal ReaderSerialNumber As String) Implements DPFP.Capture.EventHandler.OnFingerTouch
        Try

            MakeReport("The fingerprint reader was touched.")

        Catch ex As Exception
            ErrMsg(ex, GetCurrentMethod.Name)
        End Try
    End Sub
    Private Sub OnFingerGone(ByVal Capture As Object, ByVal ReaderSerialNumber As String) Implements DPFP.Capture.EventHandler.OnFingerGone
        Try

            MakeReport("The finger was removed from the fingerprint reader.")

        Catch ex As Exception
            ErrMsg(ex, GetCurrentMethod.Name)
        End Try
    End Sub

    Private Sub OnComplete(ByVal Capture As Object, ByVal ReaderSerialNumber As String, ByVal Sample As DPFP.Sample) Implements DPFP.Capture.EventHandler.OnComplete
        Try

            MakeReport("The fingerprint sample was captured.")

            If theModule = Thumb.Enrol Then
                Process_Enrol(Sample)
            Else
                Process_Verify(Sample)
            End If

        Catch ex As Exception
            ErrMsg(ex, GetCurrentMethod.Name)
        End Try
    End Sub

    Private Sub OnSampleQuality(ByVal Capture As Object, ByVal ReaderSerialNumber As String, ByVal CaptureFeedback As DPFP.Capture.CaptureFeedback) Implements DPFP.Capture.EventHandler.OnSampleQuality
        Try

            If CaptureFeedback = DPFP.Capture.CaptureFeedback.Good Then
                MakeReport("The quality of the fingerprint sample is good.")
            Else
                MakeReport("The quality of the fingerprint sample is poor.")
            End If

        Catch ex As Exception
            ErrMsg(ex, GetCurrentMethod.Name)
        End Try
    End Sub

    Private Sub MakeReport(ByVal status)
        Try

            Invoke(New FunctionCall(AddressOf _MakeReport), status)

        Catch ex As Exception
            ErrMsg(ex, GetCurrentMethod.Name)
        End Try
    End Sub
    Private Sub _MakeReport(ByVal status)
        Try

            Me.txtStatus.AppendText(status + Chr(13) + Chr(10))

        Catch ex As Exception
            ErrMsg(ex, GetCurrentMethod.Name)
        End Try
    End Sub

    '------------------------------------------------------------------------------------------------------------------
    Protected Sub DrawPicture(ByVal bmp)
        Invoke(New FunctionCall(AddressOf _DrawPicture), bmp)
    End Sub
    Private Sub _DrawPicture(ByVal bmp)
        Me.PBoxThumb.Image = New Bitmap(bmp, Me.PBoxThumb.Size)
    End Sub

    Private Function ConvertSampleToBitmap(ByVal Sample As DPFP.Sample) As Bitmap
        Dim bitmap As Bitmap = Nothing

        Try

            Dim convertor As New DPFP.Capture.SampleConversion()

            convertor.ConvertToPicture(Sample, bitmap)

        Catch ex As Exception
            ErrMsg(ex, GetCurrentMethod.Name)
        End Try

        Return bitmap

    End Function

    Private Function Extract_Features(ByVal Sample As DPFP.Sample, ByVal Purpose As DPFP.Processing.DataPurpose) As DPFP.FeatureSet
        Try

            Dim extractor As New DPFP.Processing.FeatureExtraction()    ' Create a feature extractor
            Dim feedback As DPFP.Capture.CaptureFeedback = DPFP.Capture.CaptureFeedback.None
            Dim features As New DPFP.FeatureSet()

            extractor.CreateFeatureSet(Sample, Purpose, feedback, features) ' TODO: return features as a result?

            If (feedback = DPFP.Capture.CaptureFeedback.Good) Then
                Return features
            End If

        Catch ex As Exception
            ErrMsg(ex, GetCurrentMethod.Name)
        End Try

        Return Nothing

    End Function

    Protected Sub SetStatus(ByVal status)
        Try

            Invoke(New FunctionCall(AddressOf _SetStatus), status)

        Catch ex As Exception
            ErrMsg(ex, GetCurrentMethod.Name)
        End Try
    End Sub
    Private Sub _SetStatus(ByVal status)
        Try

            Me.lblCount.Text = status

        Catch ex As Exception
            ErrMsg(ex, GetCurrentMethod.Name)
        End Try
    End Sub

    'Template Enrol
    Private Sub Process_Enrol(ByVal Sample As DPFP.Sample)
        Try
            DrawPicture(ConvertSampleToBitmap(Sample))

            Dim Features_Enrol As DPFP.FeatureSet = Extract_Features(Sample, DPFP.Processing.DataPurpose.Enrollment)

            If Not Features_Enrol Is Nothing Then 'Check quality of the sample if it's good
                Try
                    MakeReport("The fingerprint feature set was created.")
                    Enroller.AddFeatures(Features_Enrol)
                Finally
                    SetStatus("Fingerprint Templates Remaining: " & Enroller.FeaturesNeeded.ToString)

                    Select Case Enroller.TemplateStatus
                        Case DPFP.Processing.Enrollment.Status.Ready 'Report success and stop capturing
                            RaiseEvent OnTemplate(Enroller.Template)
                            StopCapture()
                            SetStatus("Fingerprint Templates Completed. Save now....")

                        Case DPFP.Processing.Enrollment.Status.Failed 'Report failure and restart capturing
                            Enroller.Clear()
                            StopCapture()
                            RaiseEvent OnTemplate(Nothing)
                            StartCapture()
                    End Select
                End Try
            End If
        Catch ex As Exception
            ErrMsg(ex, GetCurrentMethod.Name)
        End Try
    End Sub

    'Template Verify
    Private Sub Process_Verify(ByVal Sample As DPFP.Sample)
        Try

            DrawPicture(ConvertSampleToBitmap(Sample))

            Dim Features_Verify As DPFP.FeatureSet = Extract_Features(Sample, DPFP.Processing.DataPurpose.Verification)
            Dim Verificator As New DPFP.Verification.Verification
            Dim result As New DPFP.Verification.Verification.Result()

            If Not Features_Verify Is Nothing Then 'Check quality of the sample if it's good
                Dim fs As MemoryStream = New MemoryStream
                Dim fs_bytes As Byte()

                Dim obj As New cQryExec
                Dim qry As String = "Select FingerImpr From [TableName] Where ID = '[PersonID]' And isThumb = 1"
                Dim dset As New DataSet

                dset = obj.ReturnDSet(qry)

                If dset.Tables(0).Rows.Count > 0 Then
                    fs_bytes = dset.Tables(0).Rows(0).Item("FingerImpr")
                    fs = New IO.MemoryStream(fs_bytes)

                    Dim Saved_Template As New DPFP.Template(fs)

                    Verificator.Verify(Features_Verify, Saved_Template, result)
                End If

                If result.Verified Then
                    MakeReport("The fingerprint was VERIFIED.")
                Else
                    MakeReport("The fingerprint was NOT VERIFIED.")
                End If
            End If

        Catch ex As Exception
            ErrMsg(ex, GetCurrentMethod.Name)
        End Try
    End Sub

    'Save -------------------------------------------------------------------------------------------------------------
    Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click
        Try

            If Enroller.FeaturesNeeded > 0 Then
                MessageBox.Show("'Insufficient Templates'." & vbCrLf & Enroller.FeaturesNeeded.ToString & "  more 'Fingerprint' scans needed.", MsgHeader, MessageBoxButtons.OK, MessageBoxIcon.Information)
                Exit Sub
            End If

            Dim obj As New cQryExec

            Dim fs As MemoryStream = New MemoryStream
            Enroller.Template.Serialize(fs)

            fs.Position = 0
            Dim br As BinaryReader = New BinaryReader(fs)
            Dim fs_bytes() As Byte = br.ReadBytes(CType(fs.Length, Int32))

            Dim cmd As SqlCommand = New SqlCommand("Update [TableName] Set FingerImpr = @FingerImpr Where ID = '[PersonID]'", mycon)
            cmd.Parameters.Add("@FingerImpr", SqlDbType.Image).Value = fs_bytes

            If mycon.State = ConnectionState.Closed Then
                mycon.Open()
            End If

            cmd.ExecuteNonQuery()

            If mycon.State <> ConnectionState.Closed Then
                mycon.Close()
            End If


            MessageBox.Show("'Fingerprint' Templates Saved successfully.", MsgHeader, MessageBoxButtons.OK, MessageBoxIcon.Information)
            btnClose_Click("", System.EventArgs.Empty)

        Catch ex As Exception
            ErrMsg(ex, GetCurrentMethod.Name)
        End Try
    End Sub

End Class

与 Digital Persona 4500 指纹集成

这里我插入dos爸爸os

 protected override void Process(DPFP.Sample Sample)
    {
        base.Process(Sample);
        var app = new Aplicacao_Biometria();
        int id = 1;
        var result = app.Listar_Planos_id(id);

        // 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
                        OnTemplate(Enroller.Template);

                        //byte[] byted;
                        //byted = Enroller.Template.Bytes;

                        MemoryStream fingerprintData = new MemoryStream();
                        Enroller.Template.Serialize(fingerprintData);
                        fingerprintData.Position = 0;
                        BinaryReader br = new BinaryReader(fingerprintData);
                        Byte[] bytes = br.ReadBytes((Int32)Enroller.Template.Bytes.Length);

                        //Insert the file into database
                        SqlConnection cn = new SqlConnection(@"Data Source=(LocalDB)\MSSQLLocalDB;
                      AttachDbFilename=c:\Users\Gabriel\Documents\Visual Studio 2015\Projects\Projeto_Fisioativa_Desktop\Projeto_Fisioativa_Desktop2\Bd_Fisio_Desktop.mdf;
                      Integrated Security=True;
                      Connect Timeout=30;");
                        SqlCommand cmd;

                        if (result.Count != 0)
                        {
                            cmd = new SqlCommand("UPDATE Biometrias set biometria = @biometria, id_usuario = @id_usuario ", cn);
                            cmd.Parameters.Add("biometria", SqlDbType.Binary).Value = bytes;
                            cmd.Parameters.Add("id_usuario", SqlDbType.Int).Value = id;
                        }
                        else
                        {
                            cmd = new SqlCommand("INSERT INTO Biometrias VALUES(@biometria, @id_usuario)", cn);
                            cmd.Parameters.Add("biometria", SqlDbType.Binary).Value = bytes;
                            cmd.Parameters.Add("id_usuario", SqlDbType.Int).Value = 1;
                        }



                        cn.Open();
                        cmd.ExecuteNonQuery();
                        cn.Close();

                        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;
                }
            }
    }

这里我从银行搜索os爸爸os并进行比较

protected override void Process(DPFP.Sample Sample)
    {
        SqlConnection conn = new SqlConnection("Your connection string");
        conn.Open();
        SqlCommand cmd = new SqlCommand("select * from Biometrias", conn);
        SqlDataAdapter sd = new SqlDataAdapter(cmd);
        DataTable dt = new DataTable();
        sd.Fill(dt);

        foreach (DataRow dr in dt.Rows)
        {
            byte[] _img = (byte[])dr["biometria"];
            MemoryStream ms = new MemoryStream(_img);

            DPFP.Template Template = new DPFP.Template();
            Template.DeSerialize(ms);
            DPFP.Verification.Verification Verificator = new DPFP.Verification.Verification();

            base.Process(Sample);

            DPFP.FeatureSet features = ExtractFeatures(Sample, DPFP.Processing.DataPurpose.Verification);
            if (features != null)
            {
                DPFP.Verification.Verification.Result result = new DPFP.Verification.Verification.Result();
                Verificator.Verify(features, Template, ref result);
                UpdateStatus(result.FARAchieved);
                if (result.Verified)
                    MakeReport("The fingerprint was VERIFIED.");
                else
                    MakeReport("The fingerprint was NOT VERIFIED.");
            }
        }
    }
                        if (Sql.State == ConnectionState.Closed)
                        {
                            Sql.Open();
                        }

                        SqlCommand a1 = new SqlCommand("Select FingerPrint,[REF NO] 
                        from Members", Sql);
                        SqlDataReader SDR = a1.ExecuteReader();

                        while (SDR.Read())
                        {

                            ret = fpInstance.Match(CapTmp, (byte[])(SDR[0]));

                            if (ret > 30)
                            {
                                a = SDR[1].ToString();
                                break;
                            }
                        }