/// <summary> /// This method is solely responsible for creating a single template from a set of 3 or more templates. /// It uses the Neuro SDK to create a "better" template from the set provided. /// </summary> /// <param name="Templates"></param> /// <returns>IdentityStream.BioAPI.Template</returns> /// <exception cref="IdentityStream.BioAPI.GeneralizationException" /> private Template Generalize(List<Template> Templates) { NFRecord[] records = new NFRecord[Templates.Count]; for (int i = 0; i < Templates.Count; i++) { records[i] = new NFRecord(Templates[i].Data); } int baseTemplateIndex; try { NFExtractor extractor = new NFExtractor(); NFRecord record = extractor.Generalize(records, out baseTemplateIndex); extractor.Dispose(); return new Template(record.Save(), record.Minutiae.Count); } catch (Exception ex) { throw new GeneralizationException(Templates.Count, "Unable to generalize templates.", ex); } }
private bool VerifyFingerprint(student originalStudent, NFRecord template2) { const string Components = "Biometrics.FingerExtraction,Biometrics.FingerMatching"; bool matched = false; NFExtractor extractor = null; NMatcher matcher = null; try { // obtain license if (!NLicense.ObtainComponents("/local", 5000, Components)) { Console.WriteLine(@"Could not obtain licenses for components: {0}", Components); matched = false; } // create an extractor extractor = new NFExtractor(); // extract reference template NBuffer referenceTemplate = template2.Save(); //For each finger in the NFRecord // extract candidate template NBuffer leftPinkie; NBuffer leftRing; NBuffer leftMiddle; NBuffer leftIndex; NBuffer leftThumb; NBuffer rightThumb; NBuffer rightIndex; NBuffer rightMiddle; NBuffer rightRing; NBuffer rightPinkie; int scoreLeftPinkie = 0; int scoreLeftRing = 0; int scoreLeftMiddle = 0; int scoreLeftIndex = 0; int scoreLeftThumb = 0; int scoreRightPinkie = 0; int scoreRightRing = 0; int scoreRightMiddle = 0; int scoreRightIndex = 0; int scoreRightThumb = 0; // create a matcher matcher = new NMatcher(); if (originalStudent.LeftPinkie != null) { leftPinkie = originalStudent.LeftPinkie.Save(); scoreLeftPinkie = matcher.Verify(referenceTemplate, leftPinkie); } if (originalStudent.LeftRing != null) { leftRing = originalStudent.LeftRing.Save(); scoreLeftRing= matcher.Verify(referenceTemplate, leftRing); } if (originalStudent.LeftMiddle != null) { leftMiddle = originalStudent.LeftMiddle.Save(); scoreLeftMiddle= matcher.Verify(referenceTemplate, leftMiddle); } if (originalStudent.LeftIndex != null) { leftIndex = originalStudent.LeftIndex.Save(); scoreLeftIndex= matcher.Verify(referenceTemplate, leftIndex); } if (originalStudent.LeftThumb != null) { leftThumb = originalStudent.LeftThumb.Save(); scoreLeftThumb = matcher.Verify(referenceTemplate, leftThumb); } if (originalStudent.RightThumb != null) { rightThumb = originalStudent.RightThumb.Save(); scoreRightThumb = matcher.Verify(referenceTemplate, rightThumb); } if (originalStudent.RightIndex !=null) { rightIndex = originalStudent.RightIndex.Save(); scoreRightIndex = matcher.Verify(referenceTemplate, rightIndex); } if (originalStudent.RightMiddle != null) { rightMiddle = originalStudent.RightMiddle.Save(); scoreRightMiddle = matcher.Verify(referenceTemplate, rightMiddle); } if (originalStudent.RightRing != null) { rightRing = originalStudent.RightRing.Save(); scoreRightRing = matcher.Verify(referenceTemplate, rightRing); } if (originalStudent.RightPinkie != null) { rightPinkie = originalStudent.RightPinkie.Save(); scoreRightPinkie = matcher.Verify(referenceTemplate, rightPinkie); } if (scoreLeftPinkie > 0) { matched = true; matchedFingerID = 1; } if (scoreLeftRing > 0) { matched = true; matchedFingerID = 2; } if (scoreLeftMiddle > 0) { matched = true; matchedFingerID = 3; } if (scoreLeftIndex > 0) { matched = true; matchedFingerID = 4; } if (scoreLeftThumb > 0) { matched = true; matchedFingerID = 5; } if (scoreRightPinkie > 0) { matched = true; matchedFingerID = 6; } if (scoreRightRing > 0) { matched = true; matchedFingerID = 7; } if (scoreRightMiddle > 0) { matched = true; matchedFingerID = 8; } if (scoreRightIndex > 0) { matched = true; matchedFingerID = 9; } if (scoreRightThumb > 0) { matched = true; matchedFingerID = 10; } } catch (Exception ex) { Console.WriteLine(ex); //INeurotecException neurotecException = ex as INeurotecException; //if (neurotecException != null) //{ // return neurotecException.Code; //} matched = false; } finally { NLicense.ReleaseComponents(Components); if (extractor != null) { extractor.Dispose(); } if (matcher != null) { matcher.Dispose(); } } return matched; }
private void bckScanFinger_DoWork(object sender, DoWorkEventArgs e) { BackgroundWorker bck = (BackgroundWorker)sender; try { int i; NDeviceManager devMan = new NDeviceManager(NDeviceType.FingerScanner, true, false); int count = devMan.Devices.Count; //See if a fingerprint scanner is connected if (count > 0) { //What if there is more than one scanner } else { GlobalScanStatus = ScanStatus.NoScanner; } if (count > 1) //What if there is more than one scanner. We will use the first detected scanner. for (i = 0; i < count; i++) { NDevice device = devMan.Devices[i]; } i = 0; NFScanner fingerScanner = (NFScanner)devMan.Devices[i]; NFExtractor extractor = new NFExtractor(); NFRecord record; extractor.ReturnedImage = NfeReturnedImage.Binarized; NImage image = null; while (image == null && !bckScanFinger.CancellationPending) { if (bck.CancellationPending) { e.Cancel = true; } else { using ( image = fingerScanner.Capture(5000)) { if (image == null) { GlobalScanStatus = ScanStatus.NoTemplateCreated; } else { NfeExtractionStatus extractionStatus; using (NGrayscaleImage grayscaleImage = image.ToGrayscale()) { if (grayscaleImage.ResolutionIsAspectRatio || grayscaleImage.HorzResolution < 250 || grayscaleImage.VertResolution < 250) { grayscaleImage.HorzResolution = 500; grayscaleImage.VertResolution = 500; grayscaleImage.ResolutionIsAspectRatio = false; } record = extractor.Extract(grayscaleImage, NFPosition.Unknown, NFImpressionType.LiveScanPlain, out extractionStatus); fingerprintImage = (NImage)image.Clone(); fingerprintImage = NImages.GetGrayscaleColorWrapper(fingerprintImage, resultImageMinColor, resultImageMaxColor); } if (extractionStatus == NfeExtractionStatus.TemplateCreated) { GlobalScanStatus = ScanStatus.TemplateCreated; fingerprintTemplate = record; ScannedTemplated = true; bck.ReportProgress(1); } } } } } } catch (Exception ex) { ScanError = ex.Message; } GlobalScanStatus = ScanStatus.Cancelled; }
private void Scanner_ImageScanned(object sender, FPScannerImageScannedEventArgs ea) { //the lock is used to prevent a race condition //if a template is captured, capturing is set to false //a new call to StartCapturing is required in order to get the next template lock (_locker) { if (_isCapturing) { NfeExtractionStatus status; Template template = null; try { NFExtractor extractor = new NFExtractor(); NFRecord record = extractor.Extract(ea.Image, NFPosition.Unknown, NFImpressionType.LiveScanPlain, out status); template = new Template(record.Save(), record.Minutiae.Count); extractor.Dispose(); } catch (Exception ex) { OnTemplateCaptured(new TemplateCapturedEventArgs(template, TemplateCapturedStatus.ExtractorException)); return; } if (status == NfeExtractionStatus.QualityCheckFailed) { OnTemplateCaptured(new TemplateCapturedEventArgs(template, TemplateCapturedStatus.QualityCheckFailed)); return; } if (status == NfeExtractionStatus.TooFewMinutiae) { OnTemplateCaptured(new TemplateCapturedEventArgs(template, TemplateCapturedStatus.MinutiaCountFailed)); return; } OnTemplateCaptured(new TemplateCapturedEventArgs(template, TemplateCapturedStatus.Success)); } } }