Last active
November 27, 2016 02:34
-
-
Save regonn/a2ea67ca995e5c83f91beadc06023139 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # coding: utf-8 | |
| import base64 | |
| import json | |
| import requests | |
| import sys | |
| from pprint import pprint | |
| GOOGLE_CLOUD_VISION_API_URL = 'https://vision.googleapis.com/v1/images:annotate?key=' | |
| GOOGLE_API_KEY = '' | |
| DETECTION_TYPE = 'LABEL_DETECTION' | |
| # LABEL_DETECTION 画像内に写っている物体の検知、分類 | |
| # TEXT_DETECTION 画像中の文章の抽出(OCR機能) | |
| # FACE_DETECTION 画像に写っている顔情報、表情などの情報の検知 | |
| # LANDMARK_DETECTION 画像中の構造物などから、名所の検知 | |
| # LOGO_DETECTION 画像に含まれる有名なロゴの検知 | |
| # SAFE_SEARCH_DETECTION 画像に有害なコンテンツが含まれているかの判別 | |
| # IMAGE_PROPERTIES 画像に関する情報(色情報など)を取得 | |
| if __name__ == '__main__': | |
| photo_file = sys.argv[1] | |
| with open(photo_file, 'rb') as image: | |
| api_url = GOOGLE_CLOUD_VISION_API_URL + GOOGLE_API_KEY | |
| image_content = base64.b64encode(image.read()) | |
| req_body = json.dumps({ | |
| 'requests': [{ | |
| 'image': { | |
| 'content': image_content.decode('UTF-8') | |
| }, | |
| 'features': [{ | |
| 'type': DETECTION_TYPE, | |
| 'maxResults': 10 | |
| }] | |
| }] | |
| }) | |
| res = requests.post(api_url, data=req_body) | |
| pprint(res.json()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment