Skip to content

fix fingerprint save for r503 sensor example #25

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 23, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 16 additions & 4 deletions examples/fingerprint_r503_rpi.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,13 +154,25 @@ def enroll_finger(location):

def save_fingerprint_image(filename):
"""Scan fingerprint then save image to filename."""
while finger.get_image():
pass
print("Place finger on sensor...", end="", flush=True)
while True:
i = finger.get_image()
if i == adafruit_fingerprint.OK:
print("Image taken")
break
if i == adafruit_fingerprint.NOFINGER:
print(".", end="", flush=True)
elif i == adafruit_fingerprint.IMAGEFAIL:
print("Imaging error")
return False
else:
print("Other error")
return False

# let PIL take care of the image headers and file structure
from PIL import Image # pylint: disable=import-outside-toplevel

img = Image.new("L", (256, 288), "white")
img = Image.new("L", (192, 192), "white")
pixeldata = img.load()
mask = 0b00001111
result = finger.get_fpdata(sensorbuffer="image")
Expand All @@ -178,7 +190,7 @@ def save_fingerprint_image(filename):
pixeldata[x, y] = (int(result[i]) >> 4) * 17
x += 1
pixeldata[x, y] = (int(result[i]) & mask) * 17
if x == 255:
if x == 191:
x = 0
y += 1
else:
Expand Down