2017-12-19 10 views
0

OCR用GoogleのCloud Vision APIを使用します。 Pythonのサンプルコードhereを使用して、我々が持っている:私は私のAPIキーを入れてくださいGoogle Cloud Vision APIではAPIキーはどこにありますか?

def detect_text(path): 
"""Detects text in the file.""" 
client = vision.ImageAnnotatorClient() 

with io.open(path, 'rb') as image_file: 
    content = image_file.read() 

image = types.Image(content=content) 

response = client.text_detection(image=image) 
texts = response.text_annotations 
print('Texts:') 

for text in texts: 
    print('\n"{}"'.format(text.description)) 

    vertices = (['({},{})'.format(vertex.x, vertex.y) 
       for vertex in text.bounding_poly.vertices]) 

    print('bounds: {}'.format(','.join(vertices))) 

を?私は(明らかに)それなしでは認証できません。 docsから

答えて

0

あなたはクライアントライブラリのコードでサービスアカウントを使用する場合は、環境変数を設定する必要があります。

環境変数GOOGLE_APPLICATION_CREDENTIALSを設定して、アプリケーションコードに資格情報を入力します。 [PATH]を、前の手順でダウンロードしたJSONファイルの場所に置き換えます。例えば

export GOOGLE_APPLICATION_CREDENTIALS="/home/user/Downloads/service-account-file.json" 

だから、それはあなたがサービスアカウントを作成する必要がありますように資格証明書ファイルをダウンロードし、見て、それを指すように環境変数を設定します。

関連する問題