Example #1
0
def upload_fingerprint_template(name):
    myquery={}
    myquery['username'] = name
    mydoc = coll.find_one(myquery)
    #print(mydoc['uid'])
    print(mydoc['image_template'])
    image_temp = []
    image_temp = mydoc['image_template']
    print(image_temp)
    #image_temp = f.storeTemplate()
    
    try:
        f = PyFingerprint('/dev/ttyUSB0', 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))
        exit(1)
    result = image_temp
    result = f.searchTemplate()
    positionNumber = result[0]

    print('Currently used templates: ' + str(f.getTemplateCount()) +'/'+ str(f.getStorageCapacity()))
    position = f.getTemplateCount()
    position = position+1
    print("Inserting fingerprint matching user from mongo to local fingerprint sensor")
    f.uploadCharacteristics(0x01, image_temp)
    f.storeTemplate()
    print('Currently used templates: ' + str(f.getTemplateCount()) +'/'+ str(f.getStorageCapacity()))
 def LoadFingerprintIntoModule(self, inputData):
     try:
         f = PyFingerprint('/dev/ttyUSB1', 57600, 0xFFFFFFFF, 0x00000000)
         if (inputData != "null"):
             inputData = ast.literal_eval(inputData)
             f.uploadCharacteristics(0x01, inputData)
             f.storeTemplate()
         if (f.verifyPassword() == False):
             raise ValueError(
                 'The given fingerprint sensor password is wrong!')
     except Exception as e:
         pass
Example #3
0
def fingerprintGrab(ref, bucketLoc, universalLoc):
    try:
        f = PyFingerprint('/dev/ttyUSB0', 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))
        exit(1)


## Gets some sensor information
# print('Currently used templates: ' + str(f.getTemplateCount()) +'/'+ str(f.getStorageCapacity()))
    link = universalLoc + 'biom'
    ## Tries to search the finger and calculate hash
    try:
        f.deleteTemplate(0)
        char = ref.get(link, '')
        f.uploadCharacteristics(0x02, char)
        f.createTemplate()
        positionNumber = f.storeTemplate()
        auth, scan = checkAuth()
        return (auth, scan)

    except Exception as e:
        print('Operation failed!')
        print('Exception message: ' + str(e))
        exit(1)
def Adicionar_Digital():
    try:
        f = PyFingerprint('/dev/ttyUSB0', 57600, 0xFFFFFFFF, 0x00000000)
        if (f.verifyPassword() == False):
            raise ValueError('The given fingerprint sensor password is wrong!')
    except Exception as e:
        exit(1)
    try:
        while (f.readImage() == False):
            pass
        f.convertImage(0x01)
        result = f.searchTemplate()
        positionNumber = result[0]
        if (positionNumbe >= 0):
            Usr_ja_cad()
            exit(0)
            #Adicionar algo para fazer o user remover o dedo
            time.sleep(2)
            while (f.readImage() == False):
                pass
        f.convertImage(0x02)
        if (f.compareCharacteristics() == 0):
            raise Exception("Fingers not Match")
            Dedos_nao_batem()
        f.createTemplate()
        positionNumber = f.storeTemplate()
        USR = open(positionNumber + ".fin")
        USR.write(usr)
        USR.close
        Cadastrado()
        main_screen()
    except Exception as e:
        exit(1)
Example #5
0
    def threadAddFinger(self):
        ## Enrolls new finger
        ## Tries to initialize the sensor
        try:
            f = PyFingerprint(self.USB, 57600, 0xFFFFFFFF, 0x00000000)

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

        except Exception as e:
            self.lbThongBao.setText("Lỗi kết nối với cảm biên vân tay")
            self.threadIsRun = False
            return
        ## Tries to enroll new finger
        try:
            self.lbThongBao.setText("Đặt ngón tay vào cảm biến vân tay")
            ## Wait that finger is read
            while ( f.readImage() == False ):
                pass
            ## Converts read image to characteristics and stores it in charbuffer 1
            f.convertImage(0x01)
            ## Checks if finger is already enrolled
            result = f.searchTemplate()
            positionNumber = result[0]
            if ( positionNumber >= 0 ):
                self.lbThongBao.setText("Vân tay đã tồn tại")
                self.threadIsRun = False
                return

            self.lbThongBao.setText("Nhấc tay ra khỏi cảm biến")
            time.sleep(2)

            self.lbThongBao.setText("Đặt lại ngón tay lần 2 để xác thực")

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

            ## Converts read image to characteristics and stores it in charbuffer 2
            f.convertImage(0x02)

            ## Compares the charbuffers
            if ( f.compareCharacteristics() == 0 ):
                self.lbThongBao.setText("Ngón tay 2 lần không khớp nhau! Lấy Vân tay thât bại")
                self.threadIsRun = False
                return
            ## Creates a template
            f.createTemplate()
            ## Saves template at new position number
            positionNumber = f.storeTemplate()
            self.lbThongBao.setText("Thêm văn tay thành công!")
            self.threadIsRun = False

        except Exception as e:
            print('Operation failed!')
            print('Exception message: ' + str(e))
            self.lbThongBao.setText("Lỗi trong qúa trình thêm vân tay")
            self.threadIsRun = False
            return
Example #6
0
def enroll():
    ## Enrolls new finger

    try:
        finger = PyFingerprint('/dev/ttyUSB0')

        print('Waiting for finger...')
        print(finger.readImage())
        ## Wait for finger to read
        while ( finger.readImage() == False ):
            pass
        
        
        ## Converts read image to characteristics and stores it in charbuffer 1
        finger.convertImage(0x01)

     
        ## Checks if finger is already enrolled
        result = finger.searchTemplate()
        print(result)
        positionNumber = result[0]
     
        if ( positionNumber >= 0 ):
            print('Template already exists at position #' + str(positionNumber))
            return (-1)
            exit(0)
        #return True
    
        print('Remove finger...')
        time.sleep(2)
     
        print('Waiting for same finger again...')
     
        ## Wait for finger to read again
        while ( finger.readImage() == False ):
            pass
     
        ## Converts read image to characteristics and stores it in charbuffer 2
        finger.convertImage(0x02)
     
        ## Compares the charbuffers
        if ( finger.compareCharacteristics() == 0 ):
            
            raise Exception('Fingers do not match')
            return (-1)
        ## Creates a template
        finger.createTemplate()
     
        ## Saves template at new position number
        positionNumber = finger.storeTemplate()
        print('Finger enrolled successfully!')
        print('New template position #' + str(positionNumber))
        return (positionNumber)
    except Exception as e:
        print('Operation failed!')
        print('Exception message: ' + str(e))
        return (-1)
        exit(1)
        
Example #7
0
def enroll():
    f = PyFingerprint('COM6', 57600, 0xFFFFFFFF, 0x00000000)

    print('Currently used templates: ' + str(f.getTemplateCount()) + '/' +
          str(f.getStorageCapacity()))

    print('Waiting for finger...')

    while (f.readImage() == False):
        pass

    f.convertImage(FINGERPRINT_CHARBUFFER1)

    result = f.searchTemplate()
    positionNumber = result[0]

    if (positionNumber >= 0):
        print('Template already exists at position #' + str(positionNumber))
        exit(0)

    print('Remove finger...')
    time.sleep(2)

    print('Waiting for same finger again...')

    while (f.readImage() == False):
        pass

    f.convertImage(FINGERPRINT_CHARBUFFER2)

    if (f.compareCharacteristics() == 0):
        raise Exception('Fingers do not match')

    print("Nhập thông tin:")
    StudenID = input("StudentID: ")
    Name = input("Name: ")
    Class = input("Class: ")
    School = input("School: ")
    Faculty = input("Faculty: ")
    Room = input("Room: ")
    Phone = input("Phone: ")
    Email = input("Email: ")

    f.createTemplate()

    file = open('profiles/' + str(positionNumber) + '.txt',
                'w',
                encoding='UTF8')
    file.writelines("StudentID: " + StudenID + "\nName: " + Name +
                    "\nClass: " + Class + "\nSchool: " + School +
                    "\nFaculty: " + Faculty + "\nRoom: " + Room + "\nPhone: " +
                    Phone + "\nEmail: " + Email)
    file.close()

    positionNumber = f.storeTemplate()
    print('Finger enrolled successfully!')
    print('New template position #' + str(positionNumber))
def techBinFingerPrint():
    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))
    try:
        print('Waiting for finger...')

        while (f.readImage() == False):
            pass
        f.convertImage(0x01)

        result = f.searchTemplate()

        positionNumber = result[0]
        accuracyScore = result[1]
        if (positionNumber == -1):
            print('New user welcome...')
            #################################################
            print("Don't Remove finger...")
            time.sleep(2)

            print('Waiting for same finger again...')

            while (f.readImage() == False):
                pass

            f.convertImage(0x02)

            if (f.compareCharacteristics() == 0):
                raise Exception('Fingers do not match')

            f.createTemplate()

            positionNumber = f.storeTemplate()
            print('Finger enrolled successfully!')
            print('New template position #' + str(positionNumber))
            return str(positionNumber)
        else:
            print('Found template at position #' + str(positionNumber))
            return str(positionNumber)
        # print('The accuracy score is: ' + str(accuracyScore))

        f.loadTemplate(positionNumber, 0x01)

        characterics = str(f.downloadCharacteristics(0x01)).encode('utf-8')

    # print('SHA-2 hash of template: ' + hashlib.sha256(characterics).hexdigest())

    except Exception as e:
        print('Operation failed!')
        print('Exception message: ' + str(e))
class fingerprint(object):
    def __init__(self):
        self._error = None
        self._positionNumber = -1
        try:
            self.f = PyFingerprint('/dev/ttyUSB0', 57600, 0xFFFFFFFF,
                                   0x00000000)
            if (self.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))
            exit(1)

    def readFingerprint(self, buff=0x01):
        self._positionNumber = -1
        while (self.f.readImage() == False):
            pass
        self.f.convertImage(buff)
        self.result = self.f.searchTemplate()

    def searchFingerprint(self):
        try:
            self.readFingerprint()
            self._positionNumber = self.result[0]
            if (self._positionNumber <= -1): raise Exception('No match found')
        except Exception as e:
            self._error = str(e)

        return self._error, self._positionNumber

    def enrollFingerprint(self):
        try:
            self.readFingerprint()  # First Finger
            self._positionNumber = self.result[0]
            if (self._positionNumber >= 0):
                raise Exception('Fingerprint already exists')
            time.sleep(2)
            self.readFingerprint(0x02)  # Second Finger
            if (self.f.compareCharacteristics() == 0):
                raise Exception('Fingers do not match')

            #Save Fingerprint
            self.f.createTemplate()
            self._positionNumber = self.f.storeTemplate()

        except Exception as e:
            self._error = str(e)

        return self._error, self._positionNumber
Example #10
0
def enroll():
    print('start enroll')
    port = config.figerScanPort
    f = PyFingerprint(port, 57600, 0xFFFFFFFF, 0x00000000)

    ## Gets some sensor information
    print('Currently used templates: ' + str(f.getTemplateCount()) +'/'+ str(f.getStorageCapacity()))

    ## Tries to enroll new finger
    try:
        print('Waiting for finger...')
        
        ## Wait that finger is read
        timeout = time.time() + 10
        while ( f.readImage() == False ):
            test = 0
            if test == 5 or time.time() > timeout:
                print('TimeOut')
                return -2 
                break
            test = test - 1
 
        f.convertImage(0x01)

        ## Checks if finger is already enrolled
        result = f.searchTemplate()
        positionNumber = result[0]

        if ( positionNumber >= 0 ):
            print('Template already exists at position #' + str(positionNumber))
            return -1

        f.createTemplate()

        ## Saves template at new position number
        positionNumber = f.storeTemplate()
        print('Finger enrolled successfully!')
        print('New template position #' + str(positionNumber))
        return positionNumber
    
    except Exception as e:
        print('Operation failed!')
        print('Exception message: ' + str(e))
        return -2
Example #11
0
def Adicionar_Digital():
	global sc_bioAdd
	sc_bioAdd = Toplevel(screen2)
	sc_bioAdd.title("Biometria")
	sc_bioAdd.attributes('fullscreen',True)
	Label(sc_bioAdd, text = "bota o dedin aí", font = "Arial 12").pack()
	try:
		f = PyFingerprint('/dev/ttyUSB0', 57600, 0xFFFFFFFF, 0x00000000)
		if ( f.verifyPassword() == False ):
			raise ValueError('The given fingerprint sensor password is wrong!')
	except Exception as e:
			exit(1)
	try:
		Label(sc_bioAdd, text = "bota o dedin aí", font = "Arial 12").pack()
		while(f.readImage() == False):
			pass
		f.convertImage(0x01)
		result=f.searchTemplate()
		positionNumber= result[0]
		if (positionNumber >= 0):
			user_not_found()
			exit(0)
			Label(sc_bioAdd, text = "tira o dedin aí", font = "Arial 12").pack()
			time.sleep(2)
			Label(sc_bioAdd, text = "bota o dedin aí denovo", font = "Arial 12").pack()
			while(f.readImage() == False):
				pass
		f.convertImage(0x02)
		if (f.compareCharacteristics() == 0 ):
			raise Exception("Fingers not Match")
			password_not_recognised()
		f.createTemplate()
		positionNumber = f.storeTemplate()
		USR=open(positionNumber+".fin")
		USR.write(usr)
		USR.close
		Cadastrado()
		main_screen()
	except Exception as e:
		exit(1)
    def RegisterFinger():
        continue_reading = True

        try:
            f = PyFingerprint('/dev/ttyUSB0', 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))
            exit(1)

        ## Gets some sensor information
        print('Currently used templates: ' + str(f.getTemplateCount()) + '/' +
              str(f.getStorageCapacity()))

        ## Tries to enroll new finger
        try:
            Pinlbl = Label(top,
                           text="Waiting for finger...",
                           font=myfont,
                           width=16)
            Pinlbl.grid(row=0, column=3)
            Pinlbl.configure(bg='#ff7700')

            print('Waiting for finger...')

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

            ## Converts read image to characteristics and stores it in charbuffer 1
            f.convertImage(0x01)

            ## Checks if finger is already enrolled
            result = f.searchTemplate()
            positionNumber = result[0]

            print(positionNumber)

            if (positionNumber >= 0):
                print('Template already exists at position #' +
                      str(positionNumber))
                continue_reading = False

            Pinlbl = Label(top, text="Remove Finger...", font=myfont, width=16)
            Pinlbl.grid(row=0, column=3)
            Pinlbl.configure(bg='#ff7700')
            print('Remove finger...')
            time.sleep(2)

            Pinlbl = Label(top,
                           text="Waiting Same Finger Again...",
                           font=myfont,
                           width=16)
            Pinlbl.grid(row=0, column=3)
            Pinlbl.configure(bg='#ff7700')

            print('Waiting for same finger again...')

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

            ## Converts read image to characteristics and stores it in charbuffer 2
            f.convertImage(0x02)

            ## Compares the charbuffers
            if (f.compareCharacteristics() == 0):
                Pinlbl = Label(top,
                               text="Fingers do not match",
                               font=myfont,
                               width=16)
                Pinlbl.grid(row=0, column=3)
                Pinlbl.configure(bg='#ff7700')
                raise Exception('Fingers do not match')
                continue_reading = False

            ## Creates a template
            f.createTemplate()

            ## Saves template at new position number
            positionNumber = f.storeTemplate()
            Pinlbl = Label(top,
                           text="Finger enrolled successfully!",
                           font=myfont,
                           width=16)
            Pinlbl.grid(row=0, column=3)
            Pinlbl.configure(bg='#ff7700')
            print('Finger enrolled successfully!')
            print(positionNumber)
            print('New template position #' + str(positionNumber))

            Pinlbl = Label(top, text="Input Your ID", font=myfont, width=16)
            Pinlbl.grid(row=0, column=3)
            Pinlbl.configure(bg='#ff7700')

            ID = pinin.get()
            userID = ''.join(str(e) for e in ID)

            print("ID Number: ", userID)

            lockstatus = SendtoServer("/add/fingerprint/1", 1, 2, {
                'FingerPrint': str(positionNumber),
                'UserID': userID
            })
            if lockstatus['status'] == 0:
                pinlbl = Label(top,
                               text="Input Data Failed",
                               font=myfont,
                               width=16)
                Pinlbl.grid(row=0, column=3)
                Pinlbl.configure(bg='#ff7700')
                print("Tambah Data Gagal")
            else:
                Pinlbl = Label(top,
                               text="Input Data Succes",
                               font=myfont,
                               width=16)
                Pinlbl.grid(row=0, column=3)
                Pinlbl.configure(bg='#ff7700')
                print("Tambah Data Berhasil")

            continue_reading = False

        except Exception as e:
            print('Operation failed!')
            print('Exception message: ' + str(e))
            continue_reading = False
Example #13
0
def enroll():
    ## Tries to initialize the sensor
    f = PyFingerprint('COM6', 57600, 0xFFFFFFFF, 0x00000000)

    ## Gets some sensor information
    print('Currently used templates: ' + str(f.getTemplateCount()) + '/' +
          str(f.getStorageCapacity()))

    print('Waiting for finger...')

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

    ## Converts read image to characteristics and stores it in charbuffer 1
    f.convertImage(FINGERPRINT_CHARBUFFER1)

    ## Checks if finger is already enrolled
    result = f.searchTemplate()
    positionNumber = result[0]

    if (positionNumber >= 0):
        print('Template already exists at position #' + str(positionNumber))
        exit(0)

    print('Remove finger...')
    time.sleep(2)

    print('Waiting for same finger again...')

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

    ## Converts read image to characteristics and stores it in charbuffer 2
    f.convertImage(FINGERPRINT_CHARBUFFER2)

    ## Compares the charbuffers
    if (f.compareCharacteristics() == 0):
        raise Exception('Fingers do not match')

    ##
    print("Nhập thông tin:")
    StudenID = input("StudentID: ")
    Name = input("Name: ")
    Class = input("Class: ")
    School = input("School: ")
    Faculty = input("Faculty: ")
    Room = input("Room: ")
    Phone = input("Phone: ")
    Email = input("Email: ")

    file = open('profiles/2.txt', 'w', encoding='UTF8')
    file.writelines("StudentID: " + StudenID + "\nName: " + Name +
                    "\nClass: " + Class + "\nSchool: " + School +
                    "\nFaculty: " + Faculty + "\nRoom: " + Room + "\nPhone: " +
                    Phone + "\nEmail: " + Email)
    file.close()

    ## Creates a template
    f.createTemplate()

    ## Saves template at new position number
    positionNumber = f.storeTemplate()
    print('Finger enrolled successfully!')
    print('New template position #' + str(positionNumber))
Example #14
0
        print('Template already exists at position #' + str(positionNumber))
        exit(0)

    print('Remove finger...')
    time.sleep(2)

    print('Waiting for same finger again...')

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

    ## Converts read image to characteristics and stores it in charbuffer 2
    f.convertImage(0x02)

    ## Compares the charbuffers and creates a template
    f.createTemplate()

    ## Gets new position number (the counting starts at 0, so we do not need to increment)
    positionNumber = f.getTemplateCount()

    ## Saves template at new position number
    if ( f.storeTemplate(positionNumber) == True ):
        print('Finger enrolled successfully!')
        print('New template position #' + str(positionNumber))

except Exception as e:
    print('Operation failed!')
    print('Exception message: ' + str(e))
    exit(1)
Example #15
0
        time.sleep(2)

        while ( finger.readImage() == False ):
            pass

        finger.convertImage(0x02)
    
        if ( finger.compareCharacteristics() == 0 ):
            lcd.lcd_display_string('Finger patterns',1)
            lcd.lcd_display_string('do not match',2)
            exit(0)
    
    
        finger.createTemplate()
    
        positionNumber = finger.storeTemplate()
    
        lcd.lcd_clear()
        lcd.lcd_display_string('Authrization',1)
        lcd.lcd_display_string('Complete',2)
        finger.loadTemplate(positionNumber, 0x01)
        characterics = str(finger.downloadCharacteristics(0x01)).encode('utf-8')
        Char = hashlib.sha256(characterics).hexdigest()
        database.send_data("update users set user_fingerprint = '"+Char+"', pattern_position = "+str(positionNumber)+" where user_id = "+str(user_id))
        time.sleep(1)
        lcd.lcd_clear()
        lcd.lcd_display_string('User added',1)
        lcd.lcd_display_string('Finger enrolled',2)
        time.sleep(1.5)
        lcd.lcd_clear()
        lcd2.lcd_clear()
Example #16
0
    def added(self):
        print('success')
        try:
            f = PyFingerprint('/dev/ttyUSB0', 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))
            exit(1)

        ## Gets some sensor information
        print('Currently used templates: ' + str(f.getTemplateCount()) + '/' +
              str(f.getStorageCapacity()))

        ## Tries to enroll new finger
        try:
            print('Waiting for finger...')

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

            ## Converts read image to characteristics and stores it in charbuffer 1
            f.convertImage(0x01)

            ## Checks if finger is already enrolled
            result = f.searchTemplate()
            positionNumber = result[0]

            if (positionNumber >= 0):
                print('Template already exists at position #' +
                      str(positionNumber))

            print('Remove finger...')

            print('Waiting for same finger again...')

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

            ## Converts read image to characteristics and stores it in charbuffer 2
            f.convertImage(0x02)

            ## Compares the charbuffers
            if (f.compareCharacteristics() == 0):
                raise Exception('Fingers do not match')

            ## Creates a template
            f.createTemplate()

            ## Saves template at new position number
            positionNumber = f.storeTemplate()
            print('Finger enrolled successfully!')
            print('New template position #' + str(positionNumber))
            df = pd.read_csv('hostel.csv')
            roll = self.nameEdit_2.text()
            yop = self.yearedit.text()
            x = df.shape[0]
            df.set_value(x, 'Name', str(roll))
            df.set_value(x, 'fingerid', str(positionNumber))
            df.set_value(x, 'YoP', str(yop))
            df.to_csv('hostel.csv', encoding="utf-8", index=False)
            print('success')
            self.yearedit.setText("")
            self.nameEdit_2.setText("")
            self.rolledit.setText("")

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

        self.addcheck()
def finger():
    try:
        f = PyFingerprint('/dev/ttyUSB0', 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))
        exit(1)

    ## Gets some sensor information
    print('Currently used templates: ' + str(f.getTemplateCount()) + '/' +
          str(f.getStorageCapacity()))

    ## Tries to enroll new finger
    while 1:
        disp.clear()
        disp.display()
        draw.rectangle((0, 0, width, height), outline=0, fill=0)
        draw.text((x, top), 'Welcome to Enroll', font=font, fill=255)
        draw.text((x, top + 16), 'Waiting for finger...', font=font, fill=255)
        print('Waiting for finger...')
        disp.image(image)
        disp.display()
        time.sleep(.1)

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

        ## Converts read image to characteristics and stores it in charbuffer 1
        f.convertImage(0x01)

        ## Checks if finger is already enrolled
        result = f.searchTemplate()
        positionNumber = result[0]

        if (positionNumber >= 0):
            disp.clear()
            disp.display()
            draw.rectangle((0, 0, width, height), outline=0, fill=0)
            draw.text((x, top + 16),
                      'Finger already exists',
                      font=font,
                      fill=255)
            disp.image(image)
            disp.display()
            time.sleep(1)
            os.system("python password.py")
            print('Template already exists at position #' +
                  str(positionNumber))

        # disp.clear()
        # disp.display()
        # draw.rectangle((0,0,width,height), outline=0, fill=0)
        # draw.text((x, top + 16),       'Remove finger' ,  font=font, fill=255)
        # disp.image(image)
        # disp.display()
        # time.sleep(.1)
        # print('Remove finger...')
        # time.sleep(2)

        # disp.clear()
        # disp.display()
        # draw.rectangle((0,0,width,height), outline=0, fill=0)

        # draw.text((x, top + 16),       'Waiting for same' ,  font=font, fill=255)
        # draw.text((x, top + 24),       'finger again' ,  font=font, fill=255)
        # disp.image(image)
        # disp.display()

        # print('Waiting for same finger again...')
        # time.sleep(.1)

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

        # ## Converts read image to characteristics and stores it in charbuffer 2
        # f.convertImage(0x02)

        # ## Compares the charbuffers
        # if ( f.compareCharacteristics() == 0 ):
        #     disp.clear()
        #     disp.display()
        #     draw.rectangle((0,0,width,height), outline=0, fill=0)
        #     draw.text((x, top + 16),       'Fingers do not match' ,  font=font, fill=255)
        #     disp.image(image)
        #     disp.display()
        #     time.sleep(2)
        #     disp.clear()
        #     disp.display()
        #     draw.rectangle((0,0,width,height), outline=0, fill=0)
        #     os.system("python enroll_trial.py")

        ## Creates a template
        f.createTemplate()

        ## Saves template at new position number
        positionNumber = f.storeTemplate()
        print('tihis is code ', code)
        sql_enroll(code, positionNumber)

        #     print("Wrong Input")
        disp.clear()
        disp.display()
        draw.rectangle((0, 0, width, height), outline=0, fill=0)
        draw.text((x, top), 'Employee Number:', font=font, fill=255)
        draw.text((x, top + 8), code, font=font, fill=255)
        draw.text((x, top + 16), 'Employee add suceess', font=font, fill=255)
        disp.image(image)
        disp.display()
        GPIO.cleanup()
        time.sleep(2)
        os.system("python password.py")
Example #18
0
def enroll_finger():
    try:
        f = PyFingerprint('/dev/ttyUSB0', 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))
        exit(1)

    ## Gets some sensor information
    print('Currently used templates: ' + str(f.getTemplateCount()) + '/' +
          str(f.getStorageCapacity()))

    ## Tries to enroll new finger
    try:
        print('Waiting for finger...')

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

        ## Converts read image to characteristics and stores it in charbuffer 1
        f.convertImage(0x01)

        ## Checks if finger is already enrolled
        result = f.searchTemplate()
        positionNumber = result[0]

        if (positionNumber >= 0):
            print('Template already exists at position #' +
                  str(positionNumber))
            exit(0)

        print('Remove finger...')
        time.sleep(2)

        print('Waiting for same finger again...')

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

        ## Converts read image to characteristics and stores it in charbuffer 2
        f.convertImage(0x02)

        ## Compares the charbuffers
        if (f.compareCharacteristics() == 0):
            raise Exception('Fingers do not match')

        ## Creates a template
        f.createTemplate()

        ## Saves template at new position number
        positionNumber = f.storeTemplate()
        print('Finger enrolled successfully!')
        print('New template position #' + str(positionNumber))

    except Exception as e:
        print('Operation failed!')
        print('Exception message: ' + str(e))
        exit(1)
    print('Remove finger...')
    time.sleep(2)

    print('Waiting for same finger again...')

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

    ## Converts read image to characteristics and stores it in charbuffer 2
    f.convertImage(0x02)

    ## Compares the charbuffers
    if ( f.compareCharacteristics() == 0 ):
        raise Exception('Fingers do not match')

    ## Creates a template
    f.createTemplate()


    ## Saves template at new position number
    positionNumber = f.storeTemplate(charBufferNumber=0x02)
    print('Finger enrolled successfully!')
    print('New template position #' + str(positionNumber))

except Exception as e:
    print('Operation failed!')
    print('Exception message: ' + str(e))
    exit(1)
def fingerscan():
    lcd_byte(0x01,LCD_CMD)
## Tries to initialize the sensor
    try:
        f = PyFingerprint('/dev/ttyUSB0', 9600, 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))
        exit(1)

## Gets some sensor information
    print('Currently used templates: ' + str(f.getTemplateCount()) +'/'+ str(f.getStorageCapacity()))

## Tries to enroll new finger
    try:
        print('Scan Finger...')
        lcd_string("Scan Finger:",LCD_LINE_1)
    ## Wait that finger is read
        while ( f.readImage() == False ):
            pass

    ## Converts read image to characteristics and stores it in charbuffer 1
        f.convertImage(0x01)

    ## Checks if finger is already enrolled
        result = f.searchTemplate()
        positionNumber = result[0]

        if ( positionNumber >= 0 ):
            print('Template already exists at position #' + str(positionNumber))
            lcd_string("Finger ID #"+str(positionNumber),LCD_LINE_2)
            time.sleep(5)
            fingerscan()

        else:

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

    ## Converts read image to characteristics and stores it in charbuffer 2
    #    f.convertImage(0x02)

    ## Compares the charbuffers
    #    if ( f.compareCharacteristics() == 0 ):
    #        lcd_string("ERROR!",LCD_LINE_2)
    #        time.sleep(3)
    #        fingerscan()
        
    ## Creates a template
            f.createTemplate()

    ## Saves template at new position number
            positionNumber = f.storeTemplate()
            print('Finger enrolled successfully!')
            lcd_string("successfully!",LCD_LINE_2)
            print('New template position #' + str(positionNumber))

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

    return(positionNumber)
Example #21
0
    ## Wait that finger is read again
    while (f.readImage() == False):
        pass

    ## Converts read image to characteristics and stores it in charbuffer 2
    f.convertImage(0x02)

    ## Compares the charbuffers
    if (f.compareCharacteristics() == 0):
        raise Exception('Fingers do not match')

    ## Creates a template
    f.createTemplate()

    ## Saves template at new position number
    positionNumber = f.storeTemplate()
    print('Finger enrolled successfully!')
    print('New template position #' + str(positionNumber))

    f.loadTemplate(positionNumber, 0x01)

    ## Downloads the characteristics of template loaded in charbuffer 1
    characterics = str(f.downloadCharacteristics(0x01)).encode('utf-8')

    ## Hashes characteristics of template
    print('SHA-2 hash of template: ' +
          hashlib.sha256(characterics).hexdigest())

except Exception as e:
    print('Operation failed!')
    print('Exception message: ' + str(e))
Example #22
0
class fingerprint_sensor:
    def __init__(self):
        # Sensor Initialisation
        try:
            self.f = PyFingerprint('/dev/ttyUSB0', 57600, 0xFFFFFFFF,
                                   0x00000000)

            if (self.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))

    def enrollment(self):
        try:
            print('Waiting for finger...')

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

            # Converts read image to characteristics and stores it in charbuffer 1
            self.f.convertImage(0x01)

            # Checks if finger is already enrolled
            result = self.f.searchTemplate()
            positionNumber = result[0]

            if (positionNumber >= 0):
                print('Template already exists at position #' +
                      str(positionNumber))

            time.sleep(2)

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

            # Converts read image to characteristics and stores it in charbuffer 2
            self.f.convertImage(0x02)

            # Compares the charbuffers
            if (self.f.compareCharacteristics() == 0):
                raise Exception('Fingers do not match')

            # Creates a template
            self.f.createTemplate()

            # Saves template at new position number
            positionNumber = self.f.storeTemplate()
            print('Finger enrolled successfully!')
            print('New template position #' + str(positionNumber))

            # Exports the template to a temporaryfile
            template = self.f.downloadCharacteristics()
            temp_file = open("template.txt", "w+")
            for item in template:
                temp_file.write(str(item) + "\n")
            temp_file.close()
            return os.path.abspath('temp_file.txt')

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

    def authentication(self, file_path):
        try:
            match_flag = 0
            # Uploading the template to the sensor
            temp_file = open(file_path, "r")
            template = []
            for x in temp_file:
                template.append(int(x))
            temp_file.close()
            self.f.uploadCharacteristics(characteristicsData=template)
            Index_template = self.f.storeTemplate()

            # Tries to search the finger
            print('Waiting for finger...')

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

            # Converts read image to characteristics and stores it in charbuffer 1
            self.f.convertImage(0x01)

            # Searches template
            result = self.f.searchTemplate()

            positionNumber = result[0]

            if (positionNumber == -1):
                print('No match found!')
                match_flag = 0
            elif (positionNumber == Index_template):
                print('Matched')
                match_flag = 1

            return match_flag

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

    def Clear_Sensor(self):
        # Deleting the database
        self.f.clearDatabase()
Example #23
0
def hash():  
    try:
        f = PyFingerprint('/dev/ttyUSB0', 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))
        exit(1)

    ## Gets some sensor information
    ## Tries to enroll new finger
    try:
        lcddeneme.yaz("Parmaginizi","okutun")
        print('Parmağınızı okutun')

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

        ## Converts read image to characteristics and stores it in charbuffer 1
        f.convertImage(0x01)

        ## Checks if finger is already enrolled
        result = f.searchTemplate()
        positionNumber = result[0]

        if ( positionNumber >= 0 ):
            lcddeneme.yaz("Parmak izi", "Zaten kayitli")
            print('Parmak izi Zaten kayıtlı')
            return -10
        lcddeneme.yaz("Parmaginizi","cekin")
        print('Parmağınızı çekin')
        time.sleep(2)
        lcddeneme.yaz("Parmaginizi","Tekrar okutun")
        print('Parmağınızı tekrar okutun')

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

        ## Converts read image to characteristics and stores it in charbuffer 2
        f.convertImage(0x02)

        ## Compares the charbuffers
        if ( f.compareCharacteristics() == 0 ):
            raise Exception('Parmak izi Algılanamadı')
            return -10
        ## Creates a template
        f.createTemplate()

        ## Saves template at new position number
        positionNumber = f.storeTemplate()
        characterics = str(f.downloadCharacteristics(0x01)).encode('utf-8')
        b=int(positionNumber)
        return (b)
    except Exception as e:
        print('İşlem başarısız')
        print(str(e))
        return -10
Example #24
0
def enroll():
    try:
        f = PyFingerprint('/dev/ttyS0', 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))

    try:
        print('Waiting for finger...')

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

    ## Converts read image to characteristics and stores it in charbuffer 1
        f.convertImage(0x01)

        ## Checks if finger is already enrolled
        result = f.searchTemplate()
        positionNumber = result[0]

        if (positionNumber >= 0):
            print('Template already exists at position #' +
                  str(positionNumber))
            return

        print('Remove finger...')
        time.sleep(2)

        print('Waiting for same finger again...')

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

    ## Converts read image to characteristics and stores it in charbuffer 2
        f.convertImage(0x02)

        ch1 = str(f.downloadCharacteristics(0x01)).encode('utf-8')
        ch2 = str(f.downloadCharacteristics(0x02)).encode('utf-8')
        hash1 = hashlib.sha256(ch1).hexdigest()
        hash2 = hashlib.sha256(ch2).hexdigest()
        print(hash1)
        print(hash2)
        ## Compares the charbuffers
        acur = f.compareCharacteristics()
        print(acur)
        if (acur == 0):
            raise Exception('Fingers do not match')

    ## Creates a template
        f.createTemplate()

        ## Saves template at new position number
        name = input('Enter name of the person')

        positionNumber = f.storeTemplate()
        print(hash1)
        print(hash2)
        print('Finger enrolled successfully!')
        print('New template position #' + str(positionNumber))

    except Exception as e:
        print('Operation failed!')
        print('Exception message: ' + str(e))
Example #25
0
class UtilFingerprint:

    #Realiza la coneccion con el fingerprint
    def __init__(self,instIndex):
       self.initFP(instIndex)

    #Realiza la coneccion con el fingerprint
    def initFP(self,instIndex):
        self.instIndex = instIndex
        try:
            self.f = PyFingerprint('/dev/ttyS0', 57600, 0xFFFFFFFF, 0x00000000)
            if ( self.f.verifyPassword() == False ):
                raise ValueError('La contrasena del sensor de huella dactilar presento un error.')
        except Exception as e:
            print('The fingerprint sensor could not be initialized!')
            print('Exception message: ' + str(e))
            exit(1)


    #Busca una huella en especifico
    def search(self,instIndex):
        self.initFP(instIndex)

        try:
            #Esperando a que sea leido el dedo
            while (self.instIndex.semaforo == False and self.f.readImage() == False ):
                pass

            if self.instIndex.semaforo == True:
                return 0
            
            #Convierte la imagen en caracteristicas 
            self.f.convertImage(0x01)

            #Se busca la imagen leida en las guardadas previamente
            result = self.f.searchTemplate()
            positionNumber = result[0]
            accuracyScore = result[1]
            
            self.instIndex.idUser = positionNumber
            self.instIndex.semaforo = True
            return positionNumber                     

        except Exception as e:
            print('Mensaje de Excepcion: ' + str(e))
            exit(1)

    #-------- Elimina una huella en el dispositivo --------
    def delete(self, positionNumber, instIndex):
        self.initFP(instIndex)
    
        try:
            if ( self.f.deleteTemplate(positionNumber) == True ):
                print('Template deleted!')
        except Exception as e:
            print('Operation failed!')
            print('Exception message: ' + str(e))
            exit(1)

    
    #---------- Verifica existencia de huella -----------
    def exist(self, instIndex):
        self.initFP(instIndex)
    
        try:
            print("Waiting for finger")

            #Escucha el fingerprint
            while self.instIndex.semaforo == False and self.f.readImage() == False:
                pass
 
            #Si se acaba el tiempo se elimina la ejecucion
            if self.instIndex.semaforo == True:
                self.instIndex.result = "timeout"
                return "timeout"

            #En caso de que se ingresara una huella se analiza
            self.f.convertImage(0x01)

            result = self.f.searchTemplate()
            positionNumber = result[0]
            self.instIndex.result = str(positionNumber)

            return str(positionNumber)+""# -1 quiere = No existe

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


    #-------- Guarda una huella en el dispositivo --------
    def save(self, instIndex):
        self.initFP(instIndex)
    
        try:            
            #Se valida que la huella se registrara correctamente
            while (self.instIndex.semaforo == False and self.f.readImage() == False):
                pass
            
            #En caso de ser eliminado desde otra clase se termina el flujo
            if self.instIndex.semaforo == True:
                self.instIndex.result = "ERROR!, debe colocar el dedo en el dispositivo"
                return 0


            self.f.convertImage(0x02)

            if(self.f.compareCharacteristics() == 0):
                self.instIndex.result = "Las huellas no coinciden"
                return 0

            self.f.createTemplate()

            positionNumber = self.f.storeTemplate()
            #print ("La posicion de la huella es " + str(positionNumber))

            self.instIndex.idUser = positionNumber
            self.instIndex.result = "Realizado con exito."
            self.instIndex.semaforo = True

        except Exception as e:
            print('Operation failed!')
            print('Exception message: ' + str(e))
            exit(1)
Example #26
0
class Biometric:
    def __init__(self):
        self.initialize()
        return

    def initialize(self):
        self.f = PyFingerprint('/dev/ttyUSB0', 57600, 0xFFFFFFFF, 0x00000000)
        if not self.f.verifyPassword():
            raise ValueError('The given fingerprint sensor password is wrong!')

    def getSureHash(self):
        hash1 = self.getFPrintHash()
        hash2 = self.getFPrintHash()
        hash3 = self.getFPrintHash()
        hash4 = self.getFPrintHash()
        return self.most_frequent()

    def most_frequent(self, List):
        counter = 0
        num = List[0]

        for i in List:
            curr_frequency = List.count(i)
            if (curr_frequency > counter):
                counter = curr_frequency
                num = i

        return num

    def getFPrintHash(self):
        # Wait that finger is read
        while not self.f.readImage():
            pass

        # Converts read image to characteristics and stores it in charbuffer 1
        self.f.convertImage(0x01)

        # Checks if finger is already enrolled
        result = self.f.searchTemplate()
        positionNumber = result[0]

        if positionNumber >= 0:
            return self.getHash(positionNumber)

        time.sleep(2)

        # Wait that finger is read again
        while not self.f.readImage():
            pass

        # Converts read image to characteristics and stores it in charbuffer 2
        self.f.convertImage(0x02)
        # Compares the charbuffers
        if self.f.compareCharacteristics() == 0:
            raise Exception('Fingers do not match')
        # Creates a template
        self.f.createTemplate()
        # Saves template at new position number
        positionNumber = self.f.storeTemplate()
        return self.getHash(positionNumber)

    def getHash(self, positionNumber):
        # Loads the found template to charbuffer 1
        self.f.loadTemplate(positionNumber, 0x01)
        # Downloads the characteristics of template loaded in charbuffer 1
        characterics = str(
            self.f.downloadCharacteristics(0x01)).encode('utf-8')
        # Hashes characteristics of template
        fprint_hash = hashlib.sha256(str(positionNumber)).hexdigest()
        return fprint_hash
    def enroll(self):

        outlog = ''

        ## Enrolls new finger
        ##

        ## Tries to initialize the sensor
        try:
            f = PyFingerprint('/dev/ttyUSB0', 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))
            outlog += ('\nThe fingerprint sensor could not be initialized!\n'+
                'Exception message: ' + str(e))
            exit(1)

        ## Gets some sensor information
        print('Currently used templates: ' + str(f.getTemplateCount()) +'/'+ str(f.getStorageCapacity()))
        outlog += ('\nCurrently used templates: ' + str(f.getTemplateCount()) +'/'+ str(f.getStorageCapacity()))

        ## Tries to enroll new finger
        try:
            print('Waiting for finger...')
            outlog += '\nWaiting for finger...'

            scanned = False

            ## Wait that finger is read
            tic = time.clock()
            toc = time.clock()
            while ( f.readImage() == False and (toc - tic < 0.1)):
                toc = time.clock()
            
            scanned = f.readImage()


            ## Converts read image to characteristics and stores it in charbuffer 1
            f.convertImage(0x01)

            ## Checks if finger is already enrolled
            result = f.searchTemplate()
            positionNumber = result[0]

            if ( positionNumber >= 0 ):
                print('Template already exists at position #' + str(positionNumber))
                outlog += '\nTemplate already exists at position #' + str(positionNumber)
                return (self.read()[0], outlog)

            print('Remove finger...')
            outlog += '\nRemove finger...'
            time.sleep(2)

            print('Waiting for same finger again...')
            outlog += '\nWaiting for same finger again...'

            ## Wait that finger is read again
            tic = time.clock()
            toc = time.clock()
            while ( f.readImage() == False and (toc - tic < 0.1)):
                toc = time.clock()
            
            scanned = f.readImage()

            if not scanned:
                print('not scanned')
                return -1

            ## Converts read image to characteristics and stores it in charbuffer 2
            f.convertImage(0x02)

            ## Compares the charbuffers
            if ( f.compareCharacteristics() == 0 ):
                outlog += '\nFingers do not match'
                raise Exception('Fingers do not match')

            ## Creates a template
            f.createTemplate()

            ## Saves template at new position number
            positionNumber = f.storeTemplate()
            print('Finger enrolled successfully!')
            outlog += '\nFinger enrolled successfully!'
            print('New template position #' + str(positionNumber))
            outlog += '\nNew template position #' + str(positionNumber)

        except Exception as e:
            print('Operation failed!')
            print('Exception message: ' + str(e))
            outlog += ('\nException message: ' + str(e))
            return (-1, outlog)
            #time.sleep(1)
            #exit(1)

        return (positionNumber, outlog)
                                    pass

                                f.convertImage(0x02)

                                if (f.compareCharacteristics() == 0):
                                    lcd.lcd_clear()
                                    lcd.lcd_display_string('Not match!', 1, 3)
                                    time.sleep(3)
                                    lcd.lcd_clear()
                                    GPIO.output(redb, GPIO.LOW)

                                    break

                                f.createTemplate()

                                f.storeTemplate()
                                lcd.lcd_clear()
                                lcd.lcd_display_string('Successfully', 1, 2)
                                time.sleep(5)
                                lcd.lcd_clear()

                            else:  #�ҡ����¹�����ͨзӡ�õ�Ǩ��¹�����͡Ѻ��¹�������������

                                lcd.lcd_clear()
                                lcd.lcd_display_string('Master finGer', 1, 1)

                                while (f.readImage() == False):
                                    pass

                                f.convertImage(0x01)
Example #29
0
        exit(0)

    print('Remove finger...')
    time.sleep(2)

    print('Waiting for same finger again...')

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

    ## Converts read image to characteristics and stores it in charbuffer 2
    f.convertImage(0x02)

    ## Compares the charbuffers
    if ( f.compareCharacteristics() == 0 ):
        raise Exception('Fingers do not match')

    ## Creates a template
    f.createTemplate()

    ## Saves template at new position number
    positionNumber = f.storeTemplate()
    print('Finger enrolled successfully!')
    print('New template position #' + str(positionNumber))

except Exception as e:
    print('Operation failed!')
    print('Exception message: ' + str(e))
    exit(1)
Example #30
0
    ## OPTIONAL stuff
    ##

    ## Loads the found template to charbuffer 1
    ## f.loadTemplate(positionNumber, 0x01)

    ## Downloads the characteristics of template loaded in charbuffer 1
    ## characterics = str(f.downloadCharacteristics(0x01)).encode('utf-8')

    #characterics = '[3, 1, 90, 11, 163, 0, 128, 14, 128, 14, 128, 6, 0, 6, 0, 6, 0, 2, 0, 6, 0, 6, 0, 6, 0, 6, 0, 6, 0, 6, 0, 6, 0, 6, 128, 6, 192, 14, 224, 30, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 54, 4, 13, 190, 82, 155, 230, 30, 49, 36, 170, 158, 95, 37, 103, 158, 37, 40, 215, 254, 50, 180, 86, 190, 63, 33, 84, 31, 52, 59, 235, 255, 73, 188, 21, 63, 46, 137, 227, 186, 37, 9, 161, 123, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 1, 88, 18, 161, 0, 128, 6, 128, 6, 0, 2, 0, 2, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 128, 0, 128, 0, 128, 0, 128, 2, 192, 2, 192, 2, 224, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 72, 144, 204, 254, 12, 17, 33, 62, 31, 145, 163, 62, 22, 29, 157, 126, 24, 164, 27, 254, 107, 40, 229, 190, 73, 49, 170, 222, 58, 181, 216, 94, 75, 193, 22, 158, 56, 134, 101, 63, 26, 170, 154, 255, 88, 174, 84, 31, 101, 142, 142, 124, 36, 60, 153, 28, 36, 191, 193, 92, 95, 14, 165, 29, 69, 151, 35, 144, 65, 28, 36, 79, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]'

    characterics = sys.argv[1]
    if (f.uploadCharacteristics(0x01, eval(characterics)) == True):
        print('Template uploaded')
    else:
        raise Exception('Error during upload')

    if (f.storeTemplate(0) == True):
        print('Template stored')
    else:
        raise Exception('Error during template storing')

    ## Hashes characteristics of template
    ## print('SHA-2 hash of template: ' + hashlib.sha256(characterics).hexdigest())

except Exception as e:
    print('Operation failed!')
    print('Exception message: ' + str(e))
    exit(1)
    def enroll(self):
        try:
            f = PyFingerprint(self.com, self.port, 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))
            exit(1)

        ## Gets some sensor information
        print('Currently used templates: ' + str(f.getTemplateCount()) + '/' +
              str(f.getStorageCapacity()))

        ## Tries to enroll new finger
        try:

            empoly_number = input(
                '\n[SET]Please input the Employee No , (ex.48628) = ')
            if len(empoly_number) == 0:
                raise Exception('Empoly number error')

            print('[INFO]Waiting for finger...')
            ## Wait that finger is read
            while (f.readImage() == False):
                pass

            ## Converts read image to characteristics and stores it in charbuffer 1
            f.convertImage(0x01)

            ## Checks if finger is already enrolled
            result = f.searchTemplate()
            positionNumber = result[0]

            if (positionNumber >= 0):
                print('Template already exists  #' + str(empoly_number))
                exit(0)

            print('Remove finger...')
            time.sleep(2)

            print('[INFO]Waiting for same finger again...')

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

            ## Converts read image to characteristics and stores it in charbuffer 2
            f.convertImage(0x02)

            ## Compares the charbuffers
            if (f.compareCharacteristics() == 0):
                raise Exception('Fingers do not match')

            ## Creates a template
            f.createTemplate()

            ## Saves template at new position number
            positionNumber = f.storeTemplate()

            cw = open("./data_log.csv", 'a+')
            cw.write(str(positionNumber) + "," + str(empoly_number) + "\n")

            print('[OK]Finger enrolled successfully!')
            print('[OK]New template position #' + str(empoly_number))

        except Exception as e:
            print('Operation failed!')
            print('Exception message: ' + str(e))
            exit(1)
def run():

    ## Tries to initialize the sensor
    try:
        f = PyFingerprint('/dev/ttyUSB0', 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))
        exit(1)

    ## Gets some sensor information
    print('Currently used templates: ' + str(f.getTemplateCount()) + '/' +
          str(f.getStorageCapacity()))

    ## Tries to enroll new finger
    try:
        msg = messagebox.showinfo("Enroll", "Press OK when Finger Ready")
        print('Waiting for finger...')

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

        ## Converts read image to characteristics and stores it in charbuffer 1
        f.convertImage(0x01)

        ## Checks if finger is already enrolled
        result = f.searchTemplate()
        positionNumber = result[0]

        if (positionNumber >= 0):
            print('Template already exists at position #' +
                  str(positionNumber))
            exit(0)

        print('Remove finger...')
        time.sleep(1)

        msg = messagebox.showinfo("Enroll", "Press OK when Finger Ready")
        print('Waiting for same finger again...')

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

        ## Converts read image to characteristics and stores it in charbuffer 2
        f.convertImage(0x02)

        ## Compares the charbuffers
        if (f.compareCharacteristics() == 0):
            raise Exception('Fingers do not match')
            run()

        ## Creates a template
        f.createTemplate()

        ## Saves template at new position number
        positionNumber = f.storeTemplate()
        #print(positionNumber)
        idnum = positionNumber

        print('Finger enrolled successfully!')
        print('New template position #' + str(positionNumber))
        idnum = positionNumber
        #template = result[0]
        firstname = input("Enter your first name: ")
        lastname = input("Enter your last name: ")
        c.execute("INSERT INTO students VALUES(?, ?, ?, ?, ?, ?);",
                  (idnum, firstname, lastname, 'NULL', 'NULL', 'NULL'))
        conn.commit()
        #conn.close()
        f = open("idtemplate.txt", "w")
        f.write(str(idnum))
        f.close
        #exit(1)

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


#run()
#top.mainloop()
Example #33
0
def enroll(keyid):
    ## Tries to initialize the sensor
    try:
        f = PyFingerprint('/dev/ttyUSB0', 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))
        return 'Sensor Error'

    ## Gets some sensor information
    #print('Currently used templates: ' + str(f.getTemplateCount()) +'/'+ str(f.getStorageCapacity()))
    fingerdata = {}
    if os.path.exists('dataset_fingers.dat'):
        with open('dataset_fingers.dat', 'rb') as rf:
            fingerdata = pickle.load(rf)
    ## Tries to enroll new finger
    try:
        print('Waiting for finger...')

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

        ## Converts read image to characteristics and stores it in charbuffer 1
        f.convertImage(0x01)

        ## Checks if finger is already enrolled
        result = f.searchTemplate()
        positionNumber = result[0]

        if (positionNumber >= 0):
            print('Finger already present!')
            return 2

        print('Remove finger...')
        time.sleep(1)

        print('Waiting for same finger again...')

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

        ## Converts read image to characteristics and stores it in charbuffer 2
        f.convertImage(0x02)

        ## Compares the charbuffers
        if (f.compareCharacteristics() == 0):
            raise Exception('Fingers do not match')

        ## Creates a template
        f.createTemplate()

        ## Saves template at new position number
        positionNumber = f.storeTemplate()
        fingerdata[str(positionNumber)] = str(keyid)
        with open('dataset_fingers.dat', 'wb') as wf:
            pickle.dump(fingerdata, wf)
        print 'Finger enrolled successfully for ' + str(keyid) + ' !'
        #print('New template position #' + str(positionNumber))
        return 'Successful'

    except Exception as e:
        print('Operation failed!')
        print('Exception message: ' + str(e))
        return 'Unknown Error'