数字角色 SDK 验证速度很慢



我想就如何改进我的 C# 代码进行数字角色 SDK 验证征求一些建议。我注意到,当我在数据库中达到 3000 条 blob 记录并将它们全部放在 DPFP 中时。模板[] 模板数组。它只是运行得很慢。

有没有更好的方法可以做到这一点?

这是我的代码:

        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!");
        }

以下是我的代码,用于从数据库中捕获并放置所有这些 blob 保存的模板: 公共DPFP。模板[] 模板数组() {

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

顺便说一下,我将C#与MySQL一起使用提前谢谢你!

嗯,我知道这是一个老问题,但仍然如此。最好使用Stopwatch来计时验证所需的时间。无论如何,您可以进行一些优化:

  • 使用for而不是foreach;

  • 不要每次在循环内都声明变量,在循环外部和在循环中重用它,

  • 不要将所有保存的模板数据放入DPFP.Template数组。
    将每个保存的模板放入循环中的DPFP.Template对象。

  • 使用StringBuilder进行字符串操作

目前,我的程序大约需要 2-4 秒来循环浏览 150 个指纹模板,具体取决于样本的质量。我确信有一种搜索算法可以提高这种情况的性能。

最新更新