I'm using Digital Persona U.are.U 4000b fingerprint reader and I have this function that verifies the fingerprint from SQL server

My problem is the loop because it takes a lot of time to compare the templates.

Please give me some advice on how can I optimize or revise my code.


Protected Sub Process(ByVal Sample As DPFP.Sample)
    con = New SqlConnection

    con.ConnectionString = "Data Source=Test;Initial Catalog=TestDB;Persist Security Info=True;User ID=sa;Password=Passw0rd"

    Dim command As String = "SELECT * FROM Bio_Emplist"

    Dim da As New SqlDataAdapter(command, con)
    Dim dtb As New DataTable
    If dtb.Rows.Count > 0 Then
        rowCount = dtb.Rows.Count
            For Each dr As DataRow In dtb.Rows
                Dim fpt As Byte() = CType(dr("Fpt"), Byte())

                Dim ms As New MemoryStream(fpt)
                Dim tmpObj As DPFP.Template = New DPFP.Template
                Dim verify As DPFP.Verification.Verification = New DPFP.Verification.Verification

                Template = tmpObj


                Dim features As DPFP.FeatureSet = ExtractFeatures(Sample, DPFP.Processing.DataPurpose.Verification)
                ' Check quality of the sample and start verification if it's good
                If Not features Is Nothing Then
                    ' Compare the feature set with our template
                    Dim result As DPFP.Verification.Verification.Result = New DPFP.Verification.Verification.Result()
                    verify.Verify(features, Template, result)

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

                        empID = dr("EmpID")
                        empFName = dr("FName")
                        empLName = dr("LName")
                        SetVerifyText(empID, empFName, empLName)
                        Exit Try
                        If rowCount = 1 Then
                            MakeReport("The fingerprint was NOT VERIFIED.")
                            rowCount = rowCount - 1
                            MakeReport("Finding Match...")
                        End If
                    End If
                End If
        Catch ex As Exception
        End Try
    End If
End Sub
  • \$\begingroup\$ Have you tried using parallel.ForEach? \$\endgroup\$ – David Wilson Aug 8 '18 at 11:24

Remove everything that is repeated in the loop and return/do the same thing. Put them outside the loop. Example, this draw the same image every time, you only need it once.


And this seems to get the same feature every time.

Dim features As DPFP.FeatureSet = ExtractFeatures(Sample, DPFP.Processing.DataPurpose.Verification)
  • \$\begingroup\$ I put the functions outside the loop it speeds up but I encountered another problem I have more than a thousand data now and it takes like 10 seconds to match a fingerprint. Thanks by the way \$\endgroup\$ – Happy Jul 31 '18 at 0:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.