1
\$\begingroup\$

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.

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
    da.Fill(dtb)
    If dtb.Rows.Count > 0 Then
        rowCount = dtb.Rows.Count
        Try
            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
                tmpObj.DeSerialize(fpt)

                DrawPicture(ConvertSampleToBitmap(Sample))

                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)
                    'UpdateStatus(result.FARAchieved)

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

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

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.

DrawPicture(ConvertSampleToBitmap(Sample))

And this seems to get the same feature every time.

Dim features As DPFP.FeatureSet = ExtractFeatures(Sample, DPFP.Processing.DataPurpose.Verification)
\$\endgroup\$
  • \$\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.