@@ -156,6 +156,41 @@ def enroll_finger(location):
156
156
157
157
return True
158
158
159
+ def save_fingerprint_image (filename ):
160
+ """Scan fingerprint then save image to filename."""
161
+ while finger .get_image ():
162
+ pass
163
+
164
+ # let PIL take care of the image headers and file structure
165
+ from PIL import Image
166
+ img = Image .new ('L' , (256 , 288 ), 'white' )
167
+ pixeldata = img .load ()
168
+ mask = 0b00001111
169
+ result = finger .get_fpdata (sensorbuffer = "image" )
170
+
171
+ # this block "unpacks" the data received from the fingerprint
172
+ # module then copies the image data to the image placeholder "img"
173
+ # pixel by pixel. please refer to section 4.2.1 of the manual for
174
+ # more details. thanks to Bastian Raschke and Danylo Esterman.
175
+ # pylint: disable=invalid-name
176
+ x = 0
177
+ # pylint: disable=invalid-name
178
+ y = 0
179
+ # pylint: disable=consider-using-enumerate
180
+ for i in range (len (result )):
181
+ pixeldata [x , y ] = (int (result [i ]) >> 4 ) * 17
182
+ x += 1
183
+ pixeldata [x , y ] = (int (result [i ]) & mask ) * 17
184
+ if x == 255 :
185
+ x = 0
186
+ y += 1
187
+ else :
188
+ x += 1
189
+
190
+ if not img .save (filename ):
191
+ return True
192
+ return False
193
+
159
194
160
195
##################################################
161
196
@@ -185,7 +220,9 @@ def get_num(max_number):
185
220
print ("e) enroll print" )
186
221
print ("f) find print" )
187
222
print ("d) delete print" )
223
+ print ("s) save fingerprint image" )
188
224
print ("r) reset library" )
225
+ print ("q) quit" )
189
226
print ("----------------" )
190
227
c = input ("> " )
191
228
@@ -201,8 +238,16 @@ def get_num(max_number):
201
238
print ("Deleted!" )
202
239
else :
203
240
print ("Failed to delete" )
241
+ if c == 's' :
242
+ if save_fingerprint_image ("fingerprint.png" ):
243
+ print ("Fingerprint image saved" )
244
+ else :
245
+ print ("Failed to save fingerprint image" )
204
246
if c == 'r' :
205
247
if finger .empty_library () == adafruit_fingerprint .OK :
206
248
print ("Library empty!" )
207
249
else :
208
250
print ("Failed to empty library" )
251
+ if c == 'q' :
252
+ print ("Exiting fingerprint example program" )
253
+ raise SystemExit
0 commit comments