-
Notifications
You must be signed in to change notification settings - Fork 0
/
verify_with_capture.py
executable file
·87 lines (64 loc) · 3.01 KB
/
verify_with_capture.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#!/usr/bin/python3
"""
This script allow for reading of a finger and comparison of this finger with thoses saved in the internal memory
of the module.
When a finger is read, the script will trigger the external script 'on_match_success.sh' if a match is found,
and 'on_match_failed.sh' if no match is found.
The script on_match_success.sh will receive two parameters, the first beeing the finger template position in module memory
and the second beeing the matching score.
When triggering external scripts, the program wait for the scripts to finish.
"""
import subprocess, sys
from time import sleep
from pyfingerprint.pyfingerprint import PyFingerprint
from pyfingerprint.pyfingerprint import FINGERPRINT_CHARBUFFER1
from pyfingerprint.pyfingerprint import FINGERPRINT_CHARBUFFER2
import os
BASE_PATH = sys.path[0]
ON_MATCH_SUCCESS_SCRIPT = BASE_PATH + '/' + 'on_match_success.sh'
ON_MATCH_FAILED_SCRIPT = BASE_PATH + '/' + 'on_match_failed.sh'
## Tries to initialize the sensor
try:
sensor = PyFingerprint('/dev/serial0', 57600, 0xFFFFFFFF, 0x00000000)
if sensor.verifyPassword() == False :
raise ValueError('The fingerprint sensor is protected by password!')
except Exception as e:
print('The fingerprint sensor could not be initialized!')
print('Exception message: {}'.format(e))
exit(1)
## Gets info about how many fingerprint are currently stored
print('Currently stored fingers: {}/{}'.format(sensor.getTemplateCount(), sensor.getStorageCapacity()))
# Infinite loop so the script never end
while True :
## Tries to search the finger and calculate hash
try:
print('Waiting for finger...')
## Wait for finger to be read as an image
while sensor.readImage() == False :
pass
## Download a peek
sensor.downloadImage('./peek.bmp')
## Converts read image to template and stores it in charbuffer 2, so we keep original image in charbuffer 1
sensor.convertImage(FINGERPRINT_CHARBUFFER1)
## Searchs for a matching template in reader internal memory
result = sensor.searchTemplate()
template_position = result[0]
accuracy_score = result[1]
## If good match, take a peek look
if accuracy_score < 100 :
os.remove('./peek.bmp')
if template_position == -1 :
print('No match found!')
print('Trigger script : {}'.format(ON_MATCH_FAILED_SCRIPT))
subprocess.call([ON_MATCH_FAILED_SCRIPT])
else:
print('Found template at position #{}'.format(template_position))
print('The accuracy score is: {}'.format(accuracy_score))
print('Trigger script : {}'.format(ON_MATCH_SUCCESS_SCRIPT))
subprocess.call([ON_MATCH_SUCCESS_SCRIPT, str(accuracy_score), str(template_position)])
except Exception as e:
print('Operation failed!')
print('Exception message: {}'.format(e))
finally :
# Wait for two second before reading another finger
sleep(2)