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