1
\$\begingroup\$

I'm creating some python script in Raspberry Pi to running fingerprint scan and compare it against database. Using this library, on raspberry start this script will get all the database record for fingerprint characteristics and the for loops will compare it. After getting about 100 records the loops is running very slow.

import RPi.GPIO as GPIO
import time
import requests
import hashlib
import MySQLdb
from pyfingerprint.pyfingerprint import PyFingerprint

def connect():
    return MySQLdb.connect(host="192.168.1.1", user="root", passwd="123456", db="abc")

GPIO.setmode(GPIO.BOARD)
GPIO.setup(18, GPIO.OUT)
GPIO.output(18, GPIO.LOW)

try:
    f = PyFingerprint('/dev/ttyUSB1', 57600, 0xFFFFFFFF, 0x00000000)

    if ( f.verifyPassword() == False ):
        raise ValueError('The given fingerprint sensor password is wrong!')

except Exception as e:
    print('The fingerprint sensor could not be initialized!')
    print('Exception message: ' + str(e))
    pass

db = connect()
cur = db.cursor()
cur.execute("SELECT * FROM fingers")
row = cur.fetchall()
while True:
    try:
        print('Waiting for finger...')
        while(f.readImage() == False):
            pass

        f.convertImage(0x01)

        for ro in row:
            ss = eval(ro[2])
            f.uploadCharacteristics(0x02,eval(ss))
            if ( f.compareCharacteristics() == 0 ):
                #print('Fingers do not match')
                pass
            else:
                #print('Finger Match')
                GPIO.output(18, GPIO.HIGH)
                time.sleep(1)
                GPIO.output(18, GPIO.LOW)
                time.sleep(1)
                break
    #db.close()

    except Exception as e:
        print('Operation failed!')
        print('Exception message: ' + str(e))
        pass

Any suggestion? Thanks

\$\endgroup\$
6
  • \$\begingroup\$ Can you explain why you are comparing the input against hundreds of fingerprints? \$\endgroup\$ – Gareth Rees Dec 4 '18 at 10:59
  • \$\begingroup\$ For attendance management system. When it match, get the employee id and save the time employee checked in \$\endgroup\$ – Chimenk Dec 4 '18 at 11:14
  • \$\begingroup\$ The usual way to use fingerprints is for authentication, not for identification. That is, users identify themselves in some other way (for example, by presenting a badge with an RFID token) and then the fingerprint authenticates the individual user. This avoids your performance problem (you only need to compare against one fingerprint), and it reduces the risk of false positives. \$\endgroup\$ – Gareth Rees Dec 4 '18 at 11:43
  • \$\begingroup\$ What does a row in your database look like? Who has access to that database (since you eval an entry from it without any checking or logging). \$\endgroup\$ – Graipher Dec 4 '18 at 13:09
  • 1
    \$\begingroup\$ @Graipher the data is like this form [90,41,67,45] but with many number in one array. It's the finger characteristics that converted into binary. This is closed system, no one have access on it. It just the 4 raspberry and one server \$\endgroup\$ – Chimenk Dec 4 '18 at 15:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.