2012-08-07 48 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個指紋模板,取決於樣品的質量。我確定有一種搜索算法可以提高這種情況下的性能。