biometry_hash_5.py 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. def fp_search():
  2. """
  3. PyFingerprint
  4. Copyright (C) 2015 Bastian Raschke <bastian.raschke@posteo.de>
  5. All rights reserved.
  6. @author: Bastian Raschke <bastian.raschke@posteo.de>
  7. """
  8. ## Search for a finger
  9. ##
  10. ## Tries to initialize the sensor
  11. try:
  12. f = PyFingerprint('/dev/ttyUSB0', 57600, 0xFFFFFFFF, 0x00000000)
  13. if ( f.verifyPassword() == False ):
  14. raise ValueError('The given fingerprint sensor password is wrong!')
  15. except Exception as e:
  16. print('The fingerprint sensor could not be initialized!')
  17. print('Exception message: ' + str(e))
  18. exit(1)
  19. ## Gets some sensor information
  20. print('Currently stored templates: ' + str(f.getTemplateCount()))
  21. ## Tries to search the finger and calculate hash
  22. try:
  23. print('Waiting for finger...')
  24. ## Wait that finger is read
  25. while ( f.readImage() == False ):
  26. pass
  27. ## Converts read image to characteristics and stores it in charbuffer 1
  28. f.convertImage(0x01)
  29. ## Searchs template
  30. result = f.searchTemplate()
  31. positionNumber = result[0]
  32. accuracyScore = result[1]
  33. if ( positionNumber == -1 ):
  34. print('No match found!')
  35. exit(0)
  36. else:
  37. print('Found template at position #' + str(positionNumber))
  38. print('The accuracy score is: ' + str(accuracyScore))
  39. ## OPTIONAL stuff
  40. ##
  41. ## Loads the found template to charbuffer 1
  42. f.loadTemplate(positionNumber, 0x01)
  43. ## Downloads the characteristics of template loaded in charbuffer 1
  44. characterics = str(f.downloadCharacteristics(0x01))
  45. ## Hashes characteristics of template
  46. print('SHA-2 hash of template: ' + hashlib.sha256(characterics).hexdigest())
  47. except Exception as e:
  48. print('Operation failed!')
  49. print('Exception message: ' + str(e))
  50. exit(1)