// enum FingerListEnum { li, lm, lr, ll, ri, rm, rr, rl, lt, rt } public UInt32 run(String regionName) { var matcher = new BioProcessor.BioProcessor(); try { matcher.enrollProbeTemplate(_fingerList, _probeTemplate); byte[][] buffer = new byte[10][]; //int rowNumber = 0; UInt32 retcode = 0; foreach (KeyValuePair<string, object> item in _cache.GetObjectsInRegion(regionName)) { //if (_gender == 1 && Regex.IsMatch(item.Key, "m$") || // _gender == 2 && Regex.IsMatch(item.Key, "w$") || // _gender == 0) if (_gender == 1 && item.Key.EndsWith("m") || _gender == 2 && item.Key.EndsWith("w") || _gender == 0) { //short numOfMatches = 0; bool matched = false; //rowNumber++; //continue; //if (rowNumber % 1000 == 0) // Console.WriteLine("Region name: {0}, row number: {1}", regionName, rowNumber); //if (_ct.IsCancellationRequested) //{ _ct.ThrowIfCancellationRequested(); //} //int i = 0; //if (Regex.Replace(item.Key, ".$", "") == "20005140") //matched = true; matched = matcher.match(_fingerList, item.Value as byte[][]); if (matched) { retcode = UInt32.Parse(Regex.Replace(item.Key, ".$", "")); break; } } } return retcode; } catch (Exception ex) { throw new Exception(ex.Message, ex.InnerException); } finally { matcher.CleanBiometrics(); } }
//public void DeserializeWSQArray(byte[][] serializedWSQArray, out ArrayList fingersCollection) //public void processRawData(byte[][] serializedWSQArray, out ArrayList fingersCollection) //{ // var bioProcessor = new BioProcessor.BioProcessor(); // try // { // //bioProcessor.DeserializeWSQArray(serializedWSQArray[0], out fingersCollection); // bioProcessor.processRawData(serializedWSQArray, out fingersCollection); // } // catch (System.Exception ex) // { // throw new System.Exception(ex.Message); // } //} //public ArrayList processEnrolledData(byte[][] serializedWSQArray) public void processEnrolledData(byte[][] serializedWSQArray, out ArrayList fingersCollection) { //ArrayList fingersCollection; var bioProcessor = new BioProcessor.BioProcessor(); try { bioProcessor.processEnrolledData(serializedWSQArray, out fingersCollection); } catch (System.Exception ex) { throw new System.Exception(ex.Message); } //return fingersCollection; }
public void SaveWSQImage(int id, byte[] buffer) { var bioProcessor = new BioProcessor.BioProcessor(); Dictionary<string, byte[]> templates = bioProcessor.GetTemplatesFromWSQImage(id, buffer); var client = new ConfigurationServiceClient(); Dictionary<string, string> settings = new Dictionary<string, string>(); foreach (KeyValuePair<string, string> kvp in client.AppSettings()) { settings.Add(kvp.Key, kvp.Value); } foreach (var kvp in client.ConnectionStrings()) { settings.Add(kvp.Key, kvp.Value); } var db = new Database(settings); db.SaveWSQTemplate(id, templates); }
public int iterateCache(String regionName) { Stopwatch st = new Stopwatch(); st.Start(); var matcher = new BioProcessor.BioProcessor(); matcher.enrollProbeTemplate(_probeTemplate); byte[][] buffer = new byte[10][]; int rowNumber = 0; int retcode = 0; foreach (KeyValuePair<string, object> item in _cache.GetObjectsInRegion(regionName)) { short numOfMatches = 0; bool matched = false; rowNumber++; //continue; //if (rowNumber % 1000 == 0) // Console.WriteLine("Region name: {0}, row number: {1}", regionName, rowNumber); if (_ct.IsCancellationRequested) { _ct.ThrowIfCancellationRequested(); } //if (item.Key == "123") //if( false) { buffer = item.Value as byte[][]; //for (int i = 0; i < buffer.Length; i++) foreach(string finger in _fingerList) { FingerListEnum f = (FingerListEnum)Enum.Parse(typeof(FingerListEnum), finger); if (buffer[(int)f] != null && (buffer[(int)f]).Length != 0) { matched = matcher.match(buffer[(int)f]); if (matched) { numOfMatches++; } } } if (_fingerList.Count == numOfMatches) { retcode = int.Parse(item.Key); break; } } } //Console.WriteLine("====== Region name: {0}, row number: {1}", regionName, rowNumber); st.Stop(); Console.WriteLine(" ----- Region name \"{0}\", time elapsed: {1}", regionName, st.Elapsed); return retcode; }
public bool verify(byte[] probeTemplate, byte[] galleryTemplate) { var matcher = new BioProcessor.BioProcessor(); return matcher.verify(probeTemplate, galleryTemplate); }
private void saveWsqInDatabase(int id, byte[] buffer) { //FileStream fs = null; try { // fs = new FileStream("lindex.wsq", FileMode.Open); // BinaryReader br = new BinaryReader(fs); // byte[] buffer = br.ReadBytes((int)fs.Length); if (System.Configuration.ConfigurationManager.AppSettings["Enroll"] == "service") { DBUtil db = new DBUtil(); db.UploadImage(IMAGE_TYPE.wsq, id, ref buffer); } else { var bioProcessor = new BioProcessor.BioProcessor(); Dictionary<string, byte[]> templates = bioProcessor.GetTemplatesFromWSQImage(id, buffer); Dictionary<string, string> settings = new Dictionary<string, string>(); foreach (var key in ConfigurationManager.AppSettings.AllKeys) { settings.Add(key, ConfigurationManager.AppSettings[key]); } foreach (ConnectionStringSettings cs in ConfigurationManager.ConnectionStrings) { settings.Add(cs.Name, cs.ConnectionString); } var db = new DAO.Database(settings); db.SaveWSQTemplate(id, templates); this.InvokeOnClick(buttonReadFingers, new MyEventArgs(0)); } //db.SaveTemplate(id, buffer); } catch (Exception ex) { toolStripStatusLabelError.ForeColor = Color.Red; toolStripStatusLabelError.Text = ex.Message; } finally { //fs.Dispose(); } }
private void processReadFingers(byte[][] buffer) { //int id; //if (TextBoxID.Text.Length == 0 || !Int32.TryParse(TextBoxID.Text, out id)) { // toolStripStatusLabelError.Text = "Please enter a valid ID"; // toolStripStatusLabelError.ForeColor = Color.Red; // return; //} else // toolStripStatusLabelError.Text = ""; //toolStripStatusLabelError.Text = string.Empty; //startProgressBar(); //System.Threading.Thread.Sleep(5000); //buttonLeftHand.Enabled = false; //buttonRightHand.Enabled = false; //buttonThumbs.Enabled = false; //tabControl1.SelectTab("tabPage3"); //Application.DoEvents(); //Dim fingersCollection As ArrayList //BioProcessor.BioProcessor bioProcessor = null; //byte[][] buffer = null; MemoryStream ms = null; //ArrayList _fingersCollection = null; try { if (buffer[0] == null || buffer[0].Length == 0) { toolStripStatusLabelError.Text = "Can't read fingers' images using ID provided"; toolStripStatusLabelError.ForeColor = Color.Red; PictureBox pbox; for (int i = 0; i < 10; i++) { pbox = this.Controls.Find("fpPictureBox" + (i + 1 < 9 ? (i + 1).ToString() : (i + 2).ToString()), true)[0] as PictureBox; pbox.Image = null; } return; } //if (System.Configuration.ConfigurationManager.AppSettings["Enroll"] == "service") //{ // var db = new DBUtil(); // buffer[0] = db.GetImageFromWebService(IMAGE_TYPE.wsq, id); //} //else //{ // Dictionary<string, string> settings = new Dictionary<string, string>(); // foreach (var key in ConfigurationManager.AppSettings.AllKeys) // { // settings.Add(key, ConfigurationManager.AppSettings[key]); // } // foreach (ConnectionStringSettings cs in ConfigurationManager.ConnectionStrings) // { // settings.Add(cs.Name, cs.ConnectionString); // } // var db = new DAO.Database(settings); // buffer = db.GetImage(DAO.IMAGE_TYPE.wsq, id); // if (buffer[0] == null || buffer[0].Length == 0) // { // toolStripStatusLabelError.Text = "Can't read fingers' images using ID provided"; // toolStripStatusLabelError.ForeColor = Color.Red; // PictureBox pbox; // for (int i = 0; i < 10; i++) // { // pbox = this.Controls.Find("fpPictureBox" + (i + 1 < 9 ? (i + 1).ToString() : (i + 2).ToString()), true)[0] as PictureBox; // pbox.Image = null; // } // return; // } // bioProcessor = new BioProcessor.BioProcessor(); //} BioProcessor.BioProcessor bioProcessor = new BioProcessor.BioProcessor(); //MemoryStream ms = null; ms = new MemoryStream(buffer[0]); //Construct a BinaryFormatter and use it to deserialize the data to the stream. var formatter = new BinaryFormatter(); // try // { formatter.Binder = new WsqSerializationBinder.GenericBinder<WsqImage>(); _fingersCollection = formatter.Deserialize(ms) as ArrayList; // } // catch (SerializationException ex) // { // toolStripStatusLabelError.ForeColor = Color.Red; // toolStripStatusLabelError.Text = ex.Message; // } // finally // { // ms.Close(); // } PictureBox pb; System.Object theLock = new System.Object(); string label = ""; Brush brush = Brushes.Transparent; int pct = 0; for (int i = 0; i <= 9; i++) { pb = this.Controls.Find("fpPictureBox" + (i + 1 < 9 ? (i + 1).ToString() : (i + 2).ToString()), true)[0] as PictureBox; if (_fingersCollection[i] != null) { WsqImage wsq = (WsqImage)_fingersCollection[i]; if (wsq == null) { pb.Image = null; continue; } lock (theLock) { buffer[0] = ARHScanner.ConvertWSQToBmp(wsq); ARHScanner.DisposeWSQImage(); } if (buffer[0] != null && buffer[0].Length < 2) continue; if (buffer[0] == null) pb.Image = null; else { using (var ms2 = new MemoryStream(buffer[0])) { if (bioProcessor != null) { if (buffer[i + 1] != null && buffer[i + 1].Length != 0) pct = bioProcessor.getImageQuality(buffer[i + 1]); else pct = 0; if (pct > 0) { label = string.Format("Q: {0:P0}", pct / 100.0); if (pct > 79) brush = Brushes.Green; else if (pct > 39) brush = Brushes.Orange; else brush = Brushes.Red; } else { label = string.Format("q: {0:P0}", 0); brush = Brushes.Red; } //Bitmap bmp = new Bitmap(nImage.ToBitmap(), new Size(65, 95)); //Bitmap bmp2 = new Bitmap(nImage.ToBitmap(), new Size(100, 120)); //Bitmap bmp2 = new Bitmap(pb.Image, new Size(100, 120)); //Bitmap bmp = new Bitmap(Image.FromStream(ms2), new Size(100, 120)); Bitmap bmp = new Bitmap(Image.FromStream(ms2)); //RectangleF rectf = new RectangleF(0.0f, 2.0f, 65.0f, 40.0f); RectangleF rectf = new RectangleF(0.0f, 8.0f, 390.0f, 260.0f); Graphics g = Graphics.FromImage(bmp); g.SmoothingMode = SmoothingMode.AntiAlias; g.InterpolationMode = InterpolationMode.HighQualityBicubic; g.PixelOffsetMode = PixelOffsetMode.HighQuality; g.DrawString(label, new Font("Areal", 46, FontStyle.Bold), brush, rectf); g.Flush(); using (var ms3 = new MemoryStream()) { bmp.Save(ms3, System.Drawing.Imaging.ImageFormat.Bmp); pb.Image = Image.FromStream(ms3); } } else { pb.Image = Image.FromStream(ms2); } pb.SizeMode = PictureBoxSizeMode.Zoom; } } } else { pb.Image = null; } } } catch (Exception ex) { toolStripStatusLabelError.ForeColor = Color.Red; toolStripStatusLabelError.Text = ex.Message; } finally { if (ms != null) ms.Close(); buttonLeftHand.Enabled = true; buttonRightHand.Enabled = true; buttonThumbs.Enabled = true; stopProgressBar(); TextBoxID.Focus(); } }