Digital Persona SDK verification is slow?

2.4k views Asked by At

I would like to ask some advice as to how to improve my C# code for Digital Persona SDK verification. I noticed that when I reached 3000 records of blob in the database and put them all together in a DPFP.Template[] template array. It just runs very slow.

Is there a better way to do this?

Here's my code:

        foreach (DPFP.Template template in templateArr)
        {
            count--;
            String my_id = empids[count].ToString();
            // Get template from storage.

            // Compare feature set with particular template.
            ver.Verify(features, template, ref res); // This code loops for all 3000 records and causes the verification to slow down.

            if (res.Verified)
            {
                SetPrompt("You Have ");
                MakeReport("LOGGED IN!");
                getEmployeeData(my_id);
                getStatus(my_id);
                break; // success
            }
        }

        if (!res.Verified)
        {
            SetPrompt("Please ");
            MakeReport("TRY AGAIN!");
        }

Here is my code to capture and put all those blob saved templates from the database: public DPFP.Template[] templateArray() {

        //String strSQL = "SELECT emp_id, fpt_template FROM tbl_employees WHERE fpt_template != ''";
        String strSQL = "SELECT emp_id, finger_template FROM tbl_fingers WHERE finger_template != ''";
        DataTable dt;
        DPFP.Template myTemplate;
        dt = this.QueryDataTable(strSQL);
        object objByte;
        byte[] bytData;

        //*** Bind Rows ***//
        if (dt.Rows.Count > 0)
        {

            DPFP.Template[] arrTemplate = new DPFP.Template[dt.Rows.Count];
            Int32 counter = dt.Rows.Count;
            foreach (DataRow dr in dt.Rows) 
            {
                //Object fpt_template = dr["fpt_template"];
                Object fpt_template = dr["finger_template"];
                objByte = (byte[])(fpt_template);
                bytData = (byte[])objByte;

                // Convert Blob data to object and then byte
                System.IO.MemoryStream ms = new System.IO.MemoryStream(bytData);
                myTemplate = new DPFP.Template(ms);
                arrTemplate[counter - 1] = myTemplate;
                counter--;
            }

            return arrTemplate;
        }

        this.Close();
        return null;
    }

By the way I'm using C# with MySQL Thank you in advance!

1

There are 1 answers

0
Harry On

Well, I know it's an old question, but still. It would be best if you can use Stopwatch to clock the verification time it take. Anyway, some optimization you can take:

  • Use for instead of foreach;

  • Don't declare variables each time inside the loop, do it outside and reuse it in the loop,

  • Don't put all the saved template data to the DPFP.Template array.
    Put each saved template to a DPFP.Template object in a loop.

  • Use StringBuilder for String operation

Currently, my program took about 2-4 seconds to loop through 150 fingerprint templates, depends on the quality of the sample. I'm sure there's a search algorithm that can improve the performance in this scenario.