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 enrollFromImage(bool toView2) { NImage nImage = null; if (System.Configuration.ConfigurationManager.AppSettings["Enroll"] != "file") { byte[] buffer = null; DBHelper.DBUtil db = new DBHelper.DBUtil(); if (System.Configuration.ConfigurationManager.AppSettings["Enroll"] == "service") { buffer = db.GetImageFromWebService(IMAGE_TYPE.picture, this.userId); } else { buffer = db.GetImage(IMAGE_TYPE.picture, this.userId); } MemoryStream ms = null; try { if (buffer != null) { ms = new MemoryStream(buffer); } if (ms != null) { nImage = NImage.FromStream(ms); } } catch (Exception ex) { ShowError(string.Format("Error creating image retrieved from database {0}", ex.Message)); return; } finally { if (ms != null) { ms.Dispose(); } } } else { if (!toView2) { nImage = NImage.FromFile(Path.GetDirectoryName(Application.ExecutablePath) + "\\Roman.jpg"); } else { nImage = NImage.FromFile(Path.GetDirectoryName(Application.ExecutablePath) + "\\Roman2.jpg"); } } try { if (!toView2) { nlView1.Image = nImage.ToBitmap(); } else { nlView2.Image = nImage.ToBitmap(); } using (NGrayscaleImage gray = nImage.ToGrayscale()) { NleDetectionDetails details; NleExtractionStatus status; try { _extractor.DetectAllFeaturePoints = Settings.Default.ExtractorDetectAllFeaturesNonLive; } catch { } NLTemplate template = _extractor.Extract(gray, out details, out status); if (status != NleExtractionStatus.TemplateCreated) { _newRecord = null; // ShowError(string.Format("Template extraction failed: {0}", status)); String descr = getStatusDescription(status); if (descr != String.Empty) { ShowError(string.Format("Template extraction failed: {0}", descr)); } else { ShowError(string.Format("Template extraction failed: {0}", status)); } return; } else { _newRecord = new FaceRecord(template, nImage, details); if (!toView2) { _enrolledTemplateList = new List <byte[]>(); _enrolledTemplateList.Add(template.Save().ToByteArray()); } else { _capturedTemplateList = new List <byte[]>(); _capturedTemplateList.Add(template.Save().ToByteArray()); } template.Dispose(); } if (!toView2) { SetImageToView(nlView1, nImage.ToBitmap(), new NleDetectionDetails[] { details }, status, 100, TimeSpan.Zero); } else { SetImageToView(nlView2, nImage.ToBitmap(), new NleDetectionDetails[] { details }, status, 100, TimeSpan.Zero); } } } catch (Exception ex) { ShowError(ex.Message); } return; }
private void enrollFromImage(bool toView2) { NImage nImage = null; if (System.Configuration.ConfigurationManager.AppSettings["Enroll"] != "file") { byte[] buffer = null; DBHelper.DBUtil db = new DBHelper.DBUtil(); if (System.Configuration.ConfigurationManager.AppSettings["Enroll"] == "service") buffer = db.GetImageFromWebService(IMAGE_TYPE.picture, this.userId); else buffer = db.GetImage(IMAGE_TYPE.picture, this.userId); MemoryStream ms = null; try { if (buffer != null) ms = new MemoryStream(buffer); if (ms != null) nImage = NImage.FromStream(ms); } catch (Exception ex) { ShowError(string.Format("Error creating image retrieved from database {0}", ex.Message)); return; } finally { if (ms != null) ms.Dispose(); } } else { if (!toView2) nImage = NImage.FromFile(Path.GetDirectoryName(Application.ExecutablePath) + "\\Roman.jpg"); else nImage = NImage.FromFile(Path.GetDirectoryName(Application.ExecutablePath) + "\\Roman2.jpg"); } try { if (!toView2) nlView1.Image = nImage.ToBitmap(); else nlView2.Image = nImage.ToBitmap(); using (NGrayscaleImage gray = nImage.ToGrayscale()) { NleDetectionDetails details; NleExtractionStatus status; try { _extractor.DetectAllFeaturePoints = Settings.Default.ExtractorDetectAllFeaturesNonLive; } catch { } NLTemplate template = _extractor.Extract(gray, out details, out status); if (status != NleExtractionStatus.TemplateCreated) { _newRecord = null; // ShowError(string.Format("Template extraction failed: {0}", status)); String descr = getStatusDescription(status); if (descr != String.Empty) ShowError(string.Format("Template extraction failed: {0}", descr)); else ShowError(string.Format("Template extraction failed: {0}", status)); return; } else { _newRecord = new FaceRecord(template, nImage, details); if (!toView2) { _enrolledTemplateList = new List<byte[]>(); _enrolledTemplateList.Add(template.Save().ToByteArray()); } else { _capturedTemplateList = new List<byte[]>(); _capturedTemplateList.Add(template.Save().ToByteArray()); } template.Dispose(); } if (!toView2) SetImageToView(nlView1, nImage.ToBitmap(), new NleDetectionDetails[] { details }, status, 100, TimeSpan.Zero); else SetImageToView(nlView2, nImage.ToBitmap(), new NleDetectionDetails[] { details }, status, 100, TimeSpan.Zero); } } catch (Exception ex) { ShowError(ex.Message); } return; }