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 delete(self, finger_id): ## Deletes a finger from sensor ## employee = Employee() ## 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 delete the template of the finger if finger_id != -1: try: if (f.deleteTemplate(finger_id) == True): employee.remove_fingerprint(employee.ftou(finger_id)) print('Template deleted!') except Exception as e: print('Operation failed!') print('Exception message: ' + str(e)) print(traceback.format_exc()) exit(1)
def index(self): ## Tries to initialize the sensor 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 show a template index table page try: page = input( 'Please enter the index page (0, 1, 2, 3) you want to see: ') page = int(page) tableIndex = f.getTemplateIndex(page) for i in range(0, len(tableIndex)): print('Template at position #' + str(i) + ' is used: ' + str(tableIndex[i])) except Exception as e: print('Operation failed!') print('Exception message: ' + str(e)) exit(1)
def search(status=2): #0 = on time 1 = tardy 2 = absent ## Search for a 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)) exit(1) ## Gets some sensor information print('Currently used templates: ' + str(f.getTemplateCount()) + '/' + str(f.getStorageCapacity())) ## Tries to search the finger and calculate hash 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) ## Searchs template result = f.searchTemplate() positionNumber = result[0] accuracyScore = result[1] if (positionNumber == -1): print('No match found!') exit(0) else: print('Found template at position #' + str(positionNumber)) set_status(str(positionNumber), status) print('The accuracy score is: ' + str(accuracyScore)) ## 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)) ## 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))
def delete_worker(self): 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 delete the template of the finger try: positionNumber = int(self.controller.template_number) if (f.deleteTemplate(positionNumber) == True): self.controller.create_info_frame('Fingerprint Deleted') self.controller.remove_from_DB() self.controller.restore_initial_frame_from_delete() print('Template deleted!') except Exception as e: print('Operation failed!') print('Exception message: ' + str(e)) exit(1)
def search(): 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] accuracyScore = result[1] if (positionNumber == -1): print('No match found!') exit(0) else: print('Found template at position #' + str(positionNumber)) print('The accuracy score is: ' + str(accuracyScore)) f = open('profiles/' + str(positionNumber) + '.txt', 'r', encoding='UTF8') for line in f: print(line, end='') f.close()
def delete(position_number): ## Tries to initialize the sensor try: f = PyFingerprint('/dev/ttyUSB0', 57600, 0xFFFFFFFF, 0x00000000) if not f.verifyPassword(): print('The given fingerprint sensor password is wrong!') return False except Exception as e: print('The fingerprint sensor could not be initialized!') print('Exception message: ' + str(e)) return False ## Gets some sensor information print('Currently used templates: ' + str(f.getTemplateCount()) +'/'+ str(f.getStorageCapacity())) ## Tries to delete the template of the finger try: position_number = int(position_number) if not f.deleteTemplate(position_number): return False else: return True except Exception as e: print('Operation failed!') print('Exception message: ' + str(e)) return False
def del1(positionNumber): 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 delete the template of the finger try: positionNumber = int(positionNumber) if (f.deleteTemplate(positionNumber) == True): print('Template deleted!') except Exception as e: print('Operation failed!') print('Exception message: ' + str(e)) exit(1)
def runScan(self): try: f = PyFingerprint(server.usbFinger, 57600, 0xFFFFFFFF, 0x00000000) if (f.verifyPassword() == False): raise ValueError( 'The given fingerprint sensor password is wrong!') print("pass van tay lan 1") except Exception as e: try: f = PyFingerprint(server.usbDieuHoa, 57600, 0xFFFFFFFF, 0x00000000) if (f.verifyPassword() == False): raise ValueError( 'The given fingerprint sensor password is wrong!') tempUSB = server.usbDieuHoa server.usbDieuHoa = server.usbFinger server.usbFinger = tempUSB print("pass van tay lan 2") except Exception as e: print('The fingerprint sensor could not be initialized!') print('Exception message: ' + str(e)) self.lbThongBao.setText("Kiểm Tra cảm biến vân tay") return print('Currently used templates: ' + str(f.getTemplateCount()) + '/' + str(f.getStorageCapacity())) try: print('Waiting for finger...') ## Wait that finger is read numC = 0 while (f.readImage() == False and self.isRun): pass # numC+=1 # if numC > 20 : # return ## Converts read image to characteristics and stores it in charbuffer 1 if self.isRun == False: return f.convertImage(0x01) ## Searchs template result = f.searchTemplate() positionNumber = result[0] accuracyScore = result[1] if (positionNumber == -1): print('No match found!') self.lbThongBao.setText("Vân tay không khớp") else: print('Khop van tay') self.isRun = False return except Exception as e: self.lbThongBao.setText("Kiểm Tra cảm biến vân tay") print('Operation failed!') print('Exception message: ' + str(e))
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 readFingerprint(self): try: # Sensor initialisieren sensor = PyFingerprint(self.__port, self.__baudrate, self.__sensoraddr, self.__password) if not sensor.verifyPassword(): logger.warning( 'The given fingerprint sensor password is wrong!') return None logger.debug('Currently used templates: ' + str(sensor.getTemplateCount()) + '/' + str(sensor.getStorageCapacity())) # Sensor-Lesen & Event-Handling logger.debug('readFingerprint() started for %s', self.__timeout) while (not self._shutdown and self.__active): # Falls der Sensor nicht permanent aktiv ist und das Aktivitätsintervall überschritten ist - Abbruch if (self.__timeout > 0 and (time.time() > self.__timeout)): self.__active = False return None if (sensor.readImage()): # Characteristics aus dem gelesenen Fingerabdruck auslesen und hinterlegen sensor.convertImage(0x01) # Datenbank nach diesen Characteristics durchsuchen result = sensor.searchTemplate() positionNumber = result[0] accuracyScore = result[1] # Input-Pin entsprechend der gefundenen Position aktivieren self.last_key = positionNumber self.last_key_time = time.time() logger.debug('Found template at position #' + str(positionNumber)) logger.debug('The accuracy score is: ' + str(accuracyScore)) # Finger entweder gar nicht oder nicht exakt genug erkannt. if (positionNumber == -1) or (accuracyScore < self.__security): # Finger unbekannt - Event ausloesen doorpi.DoorPi().event_handler( 'OnFingerprintFoundUnknown', __name__) else: # Finger bekannt - Event ausloesen doorpi.DoorPi().event_handler( 'OnFingerprintFoundKnown', __name__) # Dem Finger zugeordnete Events auslösen if (self.last_key in self._InputPins): self._fire_OnKeyDown(self.last_key, __name__) self._fire_OnKeyPressed(self.last_key, __name__) self._fire_OnKeyUp(self.last_key, __name__) except Exception as ex: logger.exception(ex)
def delete(): f = PyFingerprint('COM6', 57600, 0xFFFFFFFF, 0x00000000) print('Currently used templates: ' + str(f.getTemplateCount()) + '/' + str(f.getStorageCapacity())) positionNumber = input( 'Please enter the template position you want to delete: ') positionNumber = int(positionNumber) if (f.deleteTemplate(positionNumber) == True): print('Template deleted!')
def in_sensor(): try: f = PyFingerprint('/dev/ttyUSB0', 57600, 0xFFFFFFFF, 0x00000000) if (f.verifyPassword() == False): raise ValueError('The given fingerprint sensor password is wrong!') return f except Exception as e: print('The fingerprint sensor could not be initialized!') print('Exception message: ' + str(e)) exit(1) print('Currently used templates: ' + str(f.getTemplateCount()) + '/' + str(f.getStorageCapacity()))
def login1(): 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) print('Currently used templates: ' + str(f.getTemplateCount()) +'/'+ str(f.getStorageCapacity())) time.sleep(1) try: while ( f.readImage() == False ): pass f.convertImage(0x01) result = f.searchTemplate() ## Searchs template positionNumber = result[0] accuracyScore = result[1] if ( positionNumber == -1 ): print('No match found! Try again') time.sleep(0.5) #login() else: print('Found template at position #' + str(positionNumber)) print('The accuracy score is: ' + str(accuracyScore)) temp = positionNumber #return 0 except Exception as e: print('Operation failed!') print('Exception message: ' + str(e)) exit(1) if ( positionNumber == -1 ): print('No match found! Try again') #global login_fails #login_fails=login_fails+1 #time.sleep(0.5) #print('login_fails' + str(login_fails)) #if(login_fails <= 3): # print("Login Attempt: #" + str(login_fails)) #login1() print("Fingerprint login failed") return -1 else: temp = positionNumber return temp
def check(): f = PyFingerprint('COM6', 57600, 0xFFFFFFFF, 0x00000000) print('Currently used templates: ' + str(f.getTemplateCount()) + '/' + str(f.getStorageCapacity())) page = input('Please enter the index page (0, 1, 2, 3) you want to see: ') page = int(page) tableIndex = f.getTemplateIndex(page) for i in range(0, len(tableIndex)): print('Template at position #' + str(i) + ' is used: ' + str(tableIndex[i]))
def search(): ## Search for a 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)) exit(1) ## Gets some sensor information print('Currently used templates: ' + str(f.getTemplateCount()) + '/' + str(f.getStorageCapacity())) ## Tries to search the finger and calculate hash 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) ## Searchs template result = f.searchTemplate() positionNumber = result[0] accuracyScore = result[1] if (positionNumber == -1): print('No match found!') exit(0) else: print('Found template at position #' + str(positionNumber)) print('The accuracy score is: ' + str(accuracyScore)) return str(positionNumber) except Exception as e: print('Operation failed!') print('Exception message: ' + str(e)) exit(1)
def init_fp(lcd): while True: try: f = PyFingerprint('/dev/ttyUSB0', 57600, 0xFFFFFFFF, 0x00000000) if (f.verifyPassword() == False): print('Currently used templates: ' + str(f.getTemplateCount()) + '/' + str(f.getStorageCapacity())) raise Exception('FP password wrong!') break else: break except Exception as e: print("Some issue with FP sendor, trying again") warning_msg(lcd, e) pass return (f)
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
def initialize_sensor(self): ## Tries to initialize the sensor print('Fingerprint reader') try: f = PyFingerprint('/dev/ttyUSB0', 57600, 0xFFFFFFFF, 0x00000000) if not f.verifyPassword(): 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 None ## Gets some sensor information print('Currently used templates: ' + str(f.getTemplateCount()) + '/' + str(f.getStorageCapacity())) return f
def begin(): # Tries to initialize the sensor global Finger try: # pulled up to avoid false detection. # So we'll be setting up falling edge detection GPIO.setmode(GPIO.BCM) GPIO.setup(TOUCH_PIN, GPIO.IN, pull_up_down=GPIO.PUD_UP) Finger = PyFingerprint(FINGER_PORT, FINGER_BAUDRATE, FINGER_ADDRESS, FINGER_PASSWORD) if not Finger.verifyPassword(): raise ValueError('Password for the Fingerprint module is wrong!') # Gets some sensor information print('Fingerprint used templates: ' + str(Finger.getTemplateCount()) + '/' + str(Finger.getStorageCapacity())) return True except Exception as e: print('The fingerprint sensor could not be initialized!') print('Exception message: ' + str(e)) return False
def init_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) used = f.getTemplateCount() #0,1,2,3 = 4 print('Currently used templates: ' + str(used) + '/' + str(f.getStorageCapacity())) if (used > 0): del_me(used, f) else: print("Nothing to be deleted in module!")
def login(): 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) print('Currently used templates: ' + str(f.getTemplateCount()) + '/' + str(f.getStorageCapacity())) time.sleep(1) try: while (f.readImage() == False): pass f.convertImage(0x01) result = f.searchTemplate() ## Searchs template positionNumber = result[0] accuracyScore = result[1] temp = positionNumber if (positionNumber == -1): print('No match found! Try again') login() else: print('Found template at position #' + str(positionNumber)) print('The accuracy score is: ' + str(accuracyScore)) f.loadTemplate(positionNumber, 0x01) if (positionNumber == -1): print('No match found! Try again') login() else: result = 1 return (result) except Exception as e: print('Operation failed!') print('Exception message: ' + str(e)) exit(1)
def display(): ## Reads image and download it ## ## 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 read image and download it try: print('Waiting for finger...') ## Wait that finger is read while (f.readImage() == False): pass print('Downloading image (this take a while)...') imageDestination = tempfile.gettempdir() + '/fingerprint.bmp' f.downloadImage(imageDestination) print('The image was saved to "' + imageDestination + '".') print('Displaying fingerprint:') os.system('eog /tmp/fingerprint.bmp') except Exception as e: print('Operation failed!') print('Exception message: ' + str(e)) exit(1)
def delete(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 delete the template of the finger try: positionNumber = input( 'Please enter the template position you want to delete: ') positionNumber = int(positionNumber) if (f.deleteTemplate(positionNumber) == True): with open('./data_log.csv', 'r') as inp, open('./data_log_edit.csv', 'w') as out: writer = csv.writer(out) rows = csv.DictReader(inp) writer.writerows([['positionnumber'] + ['empolynumber']]) for row in rows: if row['positionnumber'] != str(positionNumber): writer.writerow( [row['positionnumber'], row['empolynumber']]) os.rename('./data_log_edit.csv', './data_log.csv') print('Template deleted!') except Exception as e: print('Operation failed!') print('Exception message: ' + str(e)) exit(1)
def delete_all(self): ## 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 delete the template of the finger for finger_id in range(f.getTemplateCount() + 5): try: if ( f.deleteTemplate(finger_id) == True ): print('Template deleted!') except: print('could not delete')
def search(): ## 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())) ## Tries to search the finger and calculate hash 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) ## Searchs template result = f.searchTemplate() positionNumber = result[0] accuracyScore = result[1] if (positionNumber == -1): print('No match found!') exit(0) else: print('Found template at position #' + str(positionNumber)) print('The accuracy score is: ' + str(accuracyScore)) f = open('profiles/' + str(positionNumber) + '.txt', 'r', encoding='UTF8') for line in f: print(line, end='') f.close()
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()
## ## Tries to initialize the sensor 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)) exit(1) ## Gets some sensor information print('Currently used templates: ' + str(f.getTemplateCount()) +'/'+ str(f.getStorageCapacity())) ## Tries to show a template index table page try: page = input('Please enter the index page (0, 1, 2, 3) you want to see: ') page = int(page) tableIndex = f.getTemplateIndex(page) for i in range(0, len(tableIndex)): print('Template at position #' + str(i) + ' is used: ' + str(tableIndex[i])) except Exception as e: print('Operation failed!') print('Exception message: ' + str(e)) exit(1)
## 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: 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('Operation failed!') print('Exception message: ' + str(e)) return def clear_FDB(): clearDB = yesno("HEY!!!", "Are you sure?") if clearDB == True: clear() info("HEY!!", "Operation was successful") else: info("NOTE!!", "Going back to main window ") delete_menu_window.hide() app.show() clear_FDB_btn = PushButton(delete_menu_window, text="Clear FDB", command=clear_FDB) clearDB_text = Text (delete_menu_window, text='Currently used templates: ' + str(f.getTemplateCount()) +'/'+ str(f.getStorageCapacity())) #delete menu window ends #enroll window starts def enroll(): ## Gets some sensor information print('Currently used templates: ' + str(f.getTemplateCount()) +'/'+ str(f.getStorageCapacity())) enroll_status_text1.value = 'Currently used templates: ' + str(f.getTemplateCount()) +'/'+ str(f.getStorageCapacity()) ## Tries to enroll new finger try: print('Waiting for finger...') enroll_status_text2.value = 'Waiting for finger...' ## Wait that finger is read while ( f.readImage() == False ): pass
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")