public ScanResult Scan(string referencePath, string candidatePath) { //SqlLite.Register(biometricClient); var reference = CreateSubject(referencePath, false); var candidate = CreateSubject(candidatePath, true); var result = new ScanResult(candidatePath); _biometricClient.CreateTemplate(reference); _biometricClient.CreateTemplate(candidate); var task = _biometricClient.CreateTask(NBiometricOperations.Enroll | NBiometricOperations.DetectSegments, null); candidate.Id = "Candidate_0"; task.Subjects.Add(candidate); var subjectIndex = 0; foreach (var subject in candidate.RelatedSubjects) { subject.Id = $"Candidate_{++subjectIndex}"; task.Subjects.Add(subject); } _biometricClient.PerformTask(task); result.Status = _biometricClient.Identify(reference); if (reference.MatchingResults.Count > 0) { var matchingResult = reference.MatchingResults[0]; result.Score = matchingResult.Score; var faceResults = new List <FaceResult>(); foreach (var face in candidate.Faces) { faceResults.AddRange(face.Objects.Select(attributes => new FaceResult(attributes))); } result.FaceResults = faceResults; } return(result); }
static int Main(string[] args) { Util.PrintTutorialHeader(args); if (args.Length < 2) { return(Usage()); } //========================================================================= // CHOOSE LICENCES !!! //========================================================================= // ONE of the below listed "licenses" lines is required for unlocking this sample's functionality. Choose licenses that you currently have on your device. // If you are using a TRIAL version - choose any of them. const string licenses = "FingerMatcher, FingerExtractor"; //const string licenses = "FingerFastMatcher,FaceFastMatcher,IrisFastMatcher,PalmFastMatcher,VoiceFastMatcher"; //========================================================================= //========================================================================= // TRIAL MODE //========================================================================= // Below code line determines whether TRIAL is enabled or not. To use purchased licenses, don't use below code line. // GetTrialModeFlag() method takes value from "Bin/Licenses/TrialFlag.txt" file. So to easily change mode for all our examples, modify that file. // Also you can just set TRUE to "TrialMode" property in code. NLicenseManager.TrialMode = Util.GetTrialModeFlag(); Console.WriteLine("Trial mode: " + NLicenseManager.TrialMode); //========================================================================= var anyMatchingComponent = false; try { // Obtain licenses foreach (string license in licenses.Split(',')) { if (NLicense.Obtain("/local", 5000, license)) { Console.WriteLine("Obtained license: {0}", license); anyMatchingComponent = true; } } if (!anyMatchingComponent) { throw new NotActivatedException("Could not obtain any matching license"); } using (var biometricClient = new NBiometricClient()) // Read probe template using (NSubject probeSubject = CreateSubject(args[0], "ProbeSubject")) { // Read gallery templates and enroll them NBiometricTask enrollTask = biometricClient.CreateTask(NBiometricOperations.Enroll, null); for (int i = 1; i < args.Length; ++i) { enrollTask.Subjects.Add(CreateSubject(args[i], string.Format("GallerySubject_{0}", i))); } biometricClient.PerformTask(enrollTask); NBiometricStatus status = enrollTask.Status; if (status != NBiometricStatus.Ok) { Console.WriteLine("Enrollment was unsuccessful. Status: {0}.", status); if (enrollTask.Error != null) { throw enrollTask.Error; } return(-1); } // Set matching threshold biometricClient.MatchingThreshold = 48; // Set parameter to return matching details biometricClient.MatchingWithDetails = true; // Identify probe subject status = biometricClient.Identify(probeSubject); if (status == NBiometricStatus.Ok) { foreach (var matchingResult in probeSubject.MatchingResults) { Console.WriteLine("Matched with ID: '{0}' with score {1}", matchingResult.Id, matchingResult.Score); if (matchingResult.MatchingDetails != null) { Console.WriteLine(MatchingDetailsToString(matchingResult.MatchingDetails)); } } } else if (status == NBiometricStatus.MatchNotFound) { Console.WriteLine("Match not found!"); } else { Console.WriteLine("Identification failed. Status: {0}", status); return(-1); } } return(0); } catch (Exception ex) { return(Util.PrintException(ex)); } }