2017-11-09 1 views
0

私は1つとして機能するために結合したい2つのコードに関する問題があります。私のプロジェクトは指紋を使ったクラス出席です。私はラズベリーパイでそれをやっています。マッチングが成功した後にスキャンされた指紋の画像をダウンロードする必要があります。今すぐ私は指と一致し、私のセンサーでスキャンされたイメージをダウンロードすることができ、私は別々に両方を行うことができますが、すぐにはできません。私がしたいのは、センサーに指紋を一致させ、指紋をもう一度スキャンして1つのコマンドで画像をダウンロードすることです。誰もがこれで私を助けることができますか?コードは以下の通りです:指紋を照合は2つのコードを組み合わせて1つのコマンドとして機能します

import hashlib 
from pyfingerprint.pyfingerprint import PyFingerprint 


## 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)) 

    ## 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') 

    ## 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) 

は、画像をダウンロード:

import tempfile 
from pyfingerprint.pyfingerprint import PyFingerprint 


## 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 + '".') 

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

答えて

0

何をしたい、このですか?

画像をダウンロード指紋&を一致:

import hashlib 
import tempfile 
from pyfingerprint.pyfingerprint import PyFingerprint 

## 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)) 

    ## 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') 

    ## 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)  

## 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 + '".') 

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

これはあなたの問題を解決していますが、説明のか、機能または別のファイルを使用する場合はいくつかの種類をご希望の場合は私に知らせて –

関連する問題