2012-08-07 47 views
1

我想问一些关于如何改进用于Digital Persona SDK验证的C#代码的建议。我注意到,当我在数据库中达到了blob的3000条记录时,将它们放在DPFP.Template []模板数组中。它运行速度很慢。Digital Persona SDK验证速度很慢?

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

这里是我的代码:

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

顺便说一下,我使用C#与MySQL 先谢谢您!

+0

我接受任何想法只是为了提高验证性能。我卡在这里,真的很感谢一些帮助。 :) – user1582143 2012-08-08 09:27:22

+0

嘿家伙。你解决了你的问题吗?我也遇到了同样的麻烦。我有一个3000模板数据库,识别过程需要很长时间。我正在使用相同的技术(存储,循环和逐个验证)。你解决了吗?谢谢 – 2013-02-27 18:42:04

回答

2

嗯,我知道这是一个古老的问题,但仍然。如果您可以使用Stopwatch来记录验证时间,那最好。无论如何,一些优化你可以采取:

  • 使用for代替foreach;

  • 每次不要声明变量在循环中,做到这一点之外, 重用的循环,

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

  • 使用StringBuilder为字符串操作

目前,我计划花了大约2-4秒遍历150个指纹模板,取决于样品的质量。我确定有一种搜索算法可以提高这种情况下的性能。