google APIで以下のコードを作成しましたが、入れた画像から何が検出されるのかを確かめるのが目的です。
質問1)下記コードにあるphto_fileとimage_fileのどちらに画像を入れれば良いのでしょうか?
質問2)phto_fileとimage_fileはそれぞれどのように使うのでしょうか?
質問3)これはこのファイルが完成したらターミナル上で実行するのでしょうか、それともanaconda上で実行できますか?このコードの使い方を教えてください
追加質問
4)画像認識で帰ってくるのはラベルすなわちテキストだけでしょうか?
画像を表示して認識している画像を表示させることはできますか?
google APIのコードは以下の通りで上記コードはその一部です
import argparse import base64 from googleapiclient import discovery from oauth2client.client import GoogleCredentials import os os.environ['GOOGLE_APPLICATION_CREDENTIALS']='ファイル名.json' def main(photo_file): """Run a label request on a single image""" credentials = GoogleCredentials.get_application_default() service = discovery.build('vision', 'v1', credentials=credentials) with open(photo_file, 'rb') as image: image_content = base64.b64encode(image.read()) service_request = service.images().annotate(body={ 'requests': [{ 'image': { 'content': image_content.decode('UTF-8') }, 'features': [{ 'type': 'LABEL_DETECTION', 'maxResults': 1 }] }] }) response = service_request.execute() label = response['responses'][0]['labelAnnotations'][0]['description'] print('Found label: %s for %s' % (label, photo_file)) if __name__ == '__main__': parser = argparse.ArgumentParser() parser.add_argument('image_file', help='The image you\'d like to label.') args = parser.parse_args() main(args.image_file)
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2017/05/18 04:08
2017/05/18 04:29 編集
2017/05/18 05:29