What does the `generateRandomNumber void` call in Pyfingerprint do?

0

i am trying to develop a fingerprint application in python. i'm storing fingerprints in database as strings. Like

storedPrint = "fb04e6cd868bd1fc265a69ef490deb0e5657d090f2bc249ad18886aa103ec717"

i'm using pyfinger in my project. It is successful but it's compare of read finger is slow.

pyfinger print has generaterandomnumber void . what does that void do?

And how can i compare to fingerprints fast?

Here is my code

from pyfingerprint.pyfingerprint import PyFingerprint
from base64 import b64decode
import hashlib
import pymongo

def compare_b64_fingerprint(a,b):
    'returns inverse bit error rate in percent'
    a = b64decode(a)
    b = b64decode(b)

    matching_bits  = 0
    different_bits = 0

    if len(b) != len(a):
        # trim to shortest
        shortest = min(len(a),len(b))
        longest  = max(len(a),len(b))

        a = a[:shortest]
        b = b[:shortest]

        # extra bits count as different
        different_bits = 8*(longest-shortest)

    for i in range( len(a) ):
        byte_a = ord( a[i:i+1] )
        byte_b = ord( b[i:i+1] )

        for x in range(8):
            bit_a = byte_a >> x & 1
            bit_b = byte_b >> x & 1

            if (bit_a == bit_b):
                matching_bits  +=1
            else:
                different_bits +=1

    total_bits = different_bits + matching_bits

    return float(matching_bits) / float(total_bits)

myclient = pymongo.MongoClient("mongodb://localhost:27017/")
mydb = myclient["tourniquet"]
mycol = mydb["person"]

try:
    #check usb ls /dev/ttyUSB*
    f = PyFingerprint('/dev/ttyUSB0', 57600, 0xFFFFFFFF, 0x00000000)

    if (f.verifyPassword() == False):
        raise ValueError('error')

except Exception as e:
    print('Sensor not found!')
    print('Error: ' + str(e))
    exit(1)

try:

    while True:
        print('Parmakizi bekleniyor...')

        ## Wait that finger is read
        while (f.readImage() == False):
            pass

        f.convertImage(0x01)
        characterOkunan = str(f.downloadCharacteristics(0x01)).encode('utf-8')
        sha2Okunan = hashlib.sha256(characterOkunan).hexdigest()

        #grn = f.generateRandomNumber() #Where can i use this number

        fingerPrints = mycol.find()
        for p in fingerPrints:
            # f.uploadCharacteristics(0x02, p["fprint"]) # successfull but too slow
            # result = f.compareCharacteristics()
            sha2StoredPrint =  hashlib.sha256(p["fprint"]).hexdigest()
            if compare_b64_fingerprint(sha2Okunan, sha2StoredPrint)>.8:
                print("success")
                break
except Exception as e:
    print('Error: ' + str(e))
    exit(1)


python
fingerprint
asked on Stack Overflow Mar 10, 2020 by Tolga Sahin • edited Mar 10, 2020 by plr108

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0