Verification.java 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. package com.example.utils;
  2. import com.example.types.FingerprintCompareListItem;
  3. import com.example.types.VerificationResult;
  4. import com.machinezoo.sourceafis.FingerprintMatcher;
  5. import com.machinezoo.sourceafis.FingerprintTemplate;
  6. public class Verification {
  7. private static final double MATCH_THRESHOLD = 40.0;
  8. public static VerificationResult verifyFingeprint(FingerprintTemplate fingerprintData, FingerprintCompareListItem[] givenDataToMatch, FingerprintCompareListItem[] localData) {
  9. try {
  10. FingerprintCompareListItem[] fingerprintList;
  11. double bestScore = 0;
  12. VerificationResult matchedPerson = null;
  13. // If no given Data to Match then try local data to match
  14. if (givenDataToMatch == null || givenDataToMatch.length <= 0) {
  15. fingerprintList = localData;
  16. } else {
  17. fingerprintList = givenDataToMatch;
  18. }
  19. if (fingerprintList.length <= 0) {
  20. return null;
  21. }
  22. for (FingerprintCompareListItem entry : fingerprintList) {
  23. String personName = entry.getName();
  24. int fpPosition = entry.getFingerPosition();
  25. FingerprintTemplate candidate = entry.getFingerprint();
  26. double score = new FingerprintMatcher(fingerprintData).match(candidate);
  27. if (score > bestScore) {
  28. bestScore = score;
  29. matchedPerson.setName(personName);
  30. matchedPerson.setFingerPosition(fpPosition);
  31. matchedPerson.setFingerprint(candidate);
  32. matchedPerson.setScore(bestScore);
  33. }
  34. }
  35. // Return response based on score
  36. if (bestScore >= MATCH_THRESHOLD) {
  37. System.out.println("Person Matched: " + matchedPerson.getName() + "Score: " + bestScore);
  38. return matchedPerson;
  39. } else {
  40. return null;
  41. }
  42. } catch (Exception e) {
  43. System.out.println("Exception Error" + e);
  44. return null;
  45. }
  46. }
  47. }