public FingerTemplate Deserialize(int type, byte[] data) { FingerTemplate result = null; if (SupportedBSP.Contains(type)) { result = new TemplateSG(type, data); } return(result); }
public FingerTemplate Extract(FingerImage image) { var imageSG = image as FingerImageSG; if (imageSG == null) { return(null); } int quality = 0; TemplateSG tmpl = new TemplateSG(_BSPCode); tmpl.Bytes = new byte[maxTemplateSize]; tmpl.info = FingerInfoTemplate; m_FPM.GetImageQuality(imageSG.Width, imageSG.Height, imageSG.RawData, ref quality); tmpl.info.ImageQuality = (short)quality; m_FPM.SetTemplateFormat(SGFPMTemplateFormat.ANSI378); m_FPM.CreateTemplate(tmpl.info, imageSG.RawData, tmpl.Bytes); m_FPM.GetTemplateSize(tmpl.Bytes, ref tmpl.size); return(tmpl); }
public int Match(FingerTemplate template, IEnumerable <FingerTemplate> candidates, out List <FingerTemplate> matches) { TemplateSG templateSG = template as TemplateSG; int result = m_FPM.SetTemplateFormat(SGFPMTemplateFormat.ANSI378); matches = new List <FingerTemplate>(); foreach (var canditate in candidates.OfType <TemplateSG>()) { if (canditate.BSPCode != template.BSPCode) { continue; } bool matched = false; result = m_FPM.MatchTemplate(templateSG.Bytes, canditate.Bytes, SGFPMSecurityLevel.HIGH, ref matched); if (matched) { matches.Add(canditate); } } return(matches.Count); }
private void deviceThread() { STATE state = STATE.IDLE; COMMAND com = COMMAND.NONE; List <FingerTemplate> templates = new List <FingerTemplate>(); byte[] image = null; Int32 iError = 1; int enrollCount = 0; int quality = 50; iError = m_FPM.Init(devName); iError = m_FPM.OpenDevice(devId); GetInfo(); try { while (true) { cancelToken.Token.ThrowIfCancellationRequested(); if (state == STATE.IDLE) { com = queue.Take(cancelToken.Token); } else { // non blocking take if (queue.Count > 0) { com = queue.Take(); } } switch (com) { case COMMAND.LIVECAPTURE_START: state = STATE.TEST; break; case COMMAND.ENROLLMENT_START: state = STATE.GETFINGER; enrollCount = 0; templates.Clear(); break; case COMMAND.SINGLECAPTURE_START: state = STATE.GETSINGLE; break; case COMMAND.SINGLECAPTURE_STOP: case COMMAND.LIVECAPTURE_STOP: case COMMAND.ENROLLMENT_STOP: state = STATE.IDLE; break; } com = COMMAND.NONE; switch (state) { case STATE.TEST: SendBaseMessage("Please, touch the scanner"); // iError = m_FPM.SetLedOn(false); image = new Byte[m_ImageWidth * m_ImageHeight]; try { iError = m_FPM.GetImageEx(image, TIMEOUT_CAPTURE, 0, ENROLL_QUALITY); } catch (Exception ex) { } if (iError == (Int32)SGFPMError.ERROR_NONE) { OnBiometricsCaptured(new FingerImageSG(_BSPCode, image, m_ImageWidth, m_ImageHeight)); } else if (iError == (Int32)SGFPMError.ERROR_TIME_OUT) { OnBiometricsCaptured(null); Thread.Sleep(TIMEOUT_AFTER_CAPTURE); } else if ((iError != (Int32)SGFPMError.ERROR_INVALID_PARAM) && (iError != (Int32)SGFPMError.ERROR_LINE_DROPPED)) { state = STATE.OFFLINE; Ambassador.AddMessage(new MSignal(this, MSignal.SIGNAL.DEVICE_FAILURE)); } break; case STATE.GETSINGLE: SendBaseMessage("Please, touch the scanner"); image = new Byte[m_ImageWidth * m_ImageHeight]; state = STATE.GETSINGLEIMAGE; break; case STATE.GETSINGLEIMAGE: // iError = m_FPM.SetLedOn(false); image = new Byte[m_ImageWidth * m_ImageHeight]; iError = m_FPM.GetImageEx(image,TIMEOUT_CAPTURE,0,ENROLL_QUALITY); if (iError == 0) { OnSingleCaptured(new FingerImageSG(_BSPCode,image,m_ImageWidth,m_ImageHeight)); image = new Byte[m_ImageWidth * m_ImageHeight]; state = STATE.SINGLELIFT; } else if (iError == (Int32)SGFPMError.ERROR_TIME_OUT) { Thread.Sleep(TIMEOUT_AFTER_CAPTURE); } else if ((iError != (Int32)SGFPMError.ERROR_INVALID_PARAM) && (iError != (Int32)SGFPMError.ERROR_LINE_DROPPED)) { state = STATE.OFFLINE; Ambassador.AddMessage(new MSignal(this,MSignal.SIGNAL.DEVICE_FAILURE)); } break; case STATE.SINGLELIFT: // iError = m_FPM.SetLedOn(false); iError = m_FPM.GetImageEx(image,10,0,ENROLL_QUALITY); if (iError != 0) { state = STATE.GETSINGLE; } else { Thread.Sleep(TIMEOUT_AFTER_CAPTURE); } break; case STATE.GETFINGER: SendBaseMessage("Please, touch the scanner"); image = new Byte[m_ImageWidth * m_ImageHeight]; state = STATE.GETIMAGE; break; case STATE.GETIMAGE: // iError = m_FPM.SetLedOn(false); iError = m_FPM.GetImageEx(image,10,0,ENROLL_QUALITY); if (iError == 0) { enrollCount++; FingerImageSG fingerImage = new FingerImageSG(_BSPCode,image,m_ImageWidth,m_ImageHeight); TemplateSG tmpl = Extract(fingerImage) as TemplateSG; templates.Add(tmpl); OnBiometricsCaptured(fingerImage); OnSendProgressMessage((enrollCount) * 33); if (enrollCount < 3) { state = STATE.GETEMPTY; } else { state = STATE.FINISHENROLL; } } else if (iError == (Int32)SGFPMError.ERROR_TIME_OUT) { Thread.Sleep(TIMEOUT_AFTER_CAPTURE); } else if ((iError != (Int32)SGFPMError.ERROR_INVALID_PARAM) && (iError != (Int32)SGFPMError.ERROR_LINE_DROPPED)) { state = STATE.OFFLINE; Ambassador.AddMessage(new MSignal(this,MSignal.SIGNAL.DEVICE_FAILURE)); } break; case STATE.GETEMPTY: SendBaseMessage("Please, lift your finger up"); image = new Byte[m_ImageWidth * m_ImageHeight]; state = STATE.GETEMPTYIMAGE; break; case STATE.GETEMPTYIMAGE: // iError = m_FPM.SetLedOn(false); iError = m_FPM.GetImageEx(image,10,0,ENROLL_QUALITY); if (iError != 0) { state = STATE.GETFINGER; } else { Thread.Sleep(TIMEOUT_AFTER_CAPTURE); } break; case STATE.FINISHENROLL: state = STATE.IDLE; foreach (var template in templates) { bool matched = false; m_FPM.MatchTemplate((template as TemplateSG).Bytes,(templates[templates.Count - 1] as TemplateSG).Bytes,SGFPMSecurityLevel.NORMAL,ref matched); if (!matched) { SendPopUpMessage("Can't create template, please repeat"); OnBiometricsEnrolled(null); OnSendProgressMessage(0); } OnSendProgressMessage(100); } SendPopUpMessage("Successfully registered"); OnBiometricsEnrolled(templates.ToList()); // return new copy of list break; default: break; } } } catch (Exception ex) { log.Error(ex.Message); m_FPM.CloseDevice(); } }