{"id":1999,"date":"2018-02-03T21:27:33","date_gmt":"2018-02-03T12:27:33","guid":{"rendered":"http:\/\/bezelie.com\/blog\/?page_id=1999"},"modified":"2018-02-25T13:27:52","modified_gmt":"2018-02-25T04:27:52","slug":"%e3%82%ab%e3%83%a1%e3%83%a9%e3%81%a7%e7%94%bb%e5%83%8f%e8%aa%8d%e8%ad%98%e3%81%97%e3%81%a6%e3%81%bf%e3%82%8b","status":"publish","type":"page","link":"http:\/\/bezelie.com\/blog\/?page_id=1999","title":{"rendered":"\u30ab\u30e1\u30e9\u3067\u753b\u50cf\u8a8d\u8b58\u3057\u3066\u307f\u308b"},"content":{"rendered":"<div align=\"center\"><img decoding=\"async\" src=\"http:\/\/bezelie.com\/blog\/wp-content\/uploads\/2017\/02\/IMG_1943.jpg\" width=\"320\" \/><\/div>\n<p style=\"padding-left: 30px;\">\u30fbGoogle\u306f\u69d8\u3005\u306a\u30d7\u30ed\u30b0\u30e9\u30e0\u3092\u5b89\u4fa1\u3067\u63d0\u4f9b\u3057\u3066\u304f\u308c\u3066\u3044\u307e\u3059\u304c\u3001\u3053\u3053\u3067\u306fGoogle Cloud Vision API\u3092\u4f7f\u3063\u3066\u753b\u50cf\u8a8d\u8b58\u3059\u308b\u30ed\u30dc\u30c3\u30c8\u3092\u4f5c\u3063\u3066\u307f\u307e\u3059\u3002<br \/>\n\u30fbVision API\u3092\u4f7f\u3046\u65b9\u6cd5\u306fREST\u65b9\u5f0f\u3068Cloud SDK\u3092\u4f7f\u3046\u65b9\u6cd5\u304c\u3042\u308a\u307e\u3059\u304c\u3001\u3053\u3053\u3067\u306f\u3088\u308a\u7c21\u5358\u306b\u59cb\u3081\u3089\u308c\u308bREST\u65b9\u5f0f\u3092\u8aac\u660e\u3057\u307e\u3059\u3002<\/p>\n<p style=\"text-align: center;\"><iframe loading=\"lazy\" width=\"560\" height=\"314\" src=\"\/\/www.youtube.com\/embed\/ghxp1DsWFFI\" frameborder=\"0\" allowfullscreen=\"allowfullscreen\" data-mce-fragment=\"1\"><\/iframe><\/p>\n<h5>\u4e8b\u524d\u306e\u6e96\u5099<\/h5>\n<p style=\"padding-left: 30px;\">\u30fb\u30ab\u30e1\u30e9\u3001\u30b9\u30d4\u30fc\u30ab\u30fc\u3001\u30de\u30a4\u30af\u3092\u4f7f\u3044\u307e\u3059\u306e\u3067\u3001\u3059\u3079\u3066\u6b63\u5e38\u306b\u52d5\u4f5c\u3057\u3066\u3044\u308b\u72b6\u614b\u306b\u3057\u3066\u304a\u3044\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n<h5>Google Developers Console\u3067\u306e\u8a2d\u5b9a<\/h5>\n<p style=\"padding-left: 30px;\">\u30fbgoogle\u306e\u30a2\u30ab\u30a6\u30f3\u30c8\u3092\u6301\u3063\u3066\u3044\u306a\u3044\u5834\u5408\u306f\u4f5c\u3063\u3066\u304f\u3060\u3055\u3044\u3002[<a href=\"https:\/\/accounts.google.com\/SignUp\">Google \u30a2\u30ab\u30a6\u30f3\u30c8\u306e\u4f5c\u6210<\/a>]<br \/>\n\u30fb [<a href=\"https:\/\/console.developers.google.com\/\">Google Developers Console<\/a>]\u306b\u30ed\u30b0\u30a4\u30f3\u3057\u3066\u304f\u3060\u3055\u3044\u3002<br \/>\n\u30fb\u3053\u3053\u3067\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u3092\u4f5c\u6210\u3057\u3001\u8ab2\u91d1\u3092\u6709\u52b9\u5316\u3057\u3001\u300cCloud Vision API\u300d\u3092\u6709\u52b9\u5316\u3057\u3001API\u30ad\u30fc\u3092\u751f\u6210\u3057\u307e\u3059\u3002<br \/>\n\u30fb\u65e5\u672c\u8a9e\u3067\u3068\u3066\u3082\u5206\u304b\u308a\u3084\u3059\u304f\u8aac\u660e\u3057\u3066\u3044\u308b\u30da\u30fc\u30b8\u304c\u3042\u308a\u307e\u3059\u306e\u3067\u3001\u3053\u3061\u3089\u3092\u53c2\u8003\u306b\u9032\u3081\u308b\u3068\u826f\u3044\u306e\u3067\u306f\u306a\u3044\u304b\u3068\u601d\u3044\u307e\u3059\u3002[<a href=\"https:\/\/syncer.jp\/cloud-vision-api\">syncer.jp : Cloud Vision API\u306e\u4f7f\u3044\u65b9\u307e\u3068\u3081<\/a>]<br \/>\n\u30fb\u3053\u3053\u3067\u4f5c\u6210\u3057\u305fAPI\u30ad\u30fc\u306f\u3053\u306e\u3042\u3068\u4f7f\u3046\u306e\u3067\u30b3\u30d4\u30fc\u3057\u3066\u304a\u3044\u3066\u304f\u3060\u3055\u3044\u3002<br \/>\n\u30fb\u767b\u9332\u958b\u59cb\u304b\u3089\uff16\uff10\u65e5\u9593\u306f\uff13\u4e07\u5186\u307e\u3067\u7121\u6599\u3067\u4f7f\u3048\u307e\u3059\u3002<\/p>\n<h5>API\u30ad\u30fc\u306e\u57cb\u3081\u8fbc\u307f<\/h5>\n<p style=\"padding-left: 30px;\">\u30fb\u5148\u307b\u3069\u53d6\u5f97\u3057\u305fAPI\u30ad\u30fc\u3092\u30b5\u30f3\u30d7\u30eb\u30d7\u30ed\u30b0\u30e9\u30e0\u306b\u66f8\u304d\u8fbc\u307f\u307e\u3059\u3002<br \/>\n\u30fb\u30b5\u30f3\u30d7\u30eb\u30d7\u30ed\u30b0\u30e9\u30e0\u3092\u30c6\u30ad\u30b9\u30c8\u30a8\u30c7\u30a3\u30bf\u30fc\u3067\u958b\u3044\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n<pre class=\"nums:false lang:sh decode:true \">$ sudo nano sample_vision1.py<\/pre>\n<p style=\"padding-left: 30px;\">\u30fb\uff11\uff15\u884c\u76ee\u306b\u3042\u308b\u300cAPI_KEY = &#8221; \u300d\u306e\u30af\u30a9\u30fc\u30c6\u30fc\u30b7\u30e7\u30f3\u306e\u9593\u306bAPI\u30ad\u30fc\u3092\u30da\u30fc\u30b9\u30c8\u3057\u3066\u304f\u3060\u3055\u3044\u3002<br \/>\n\u30fb\u30a8\u30c7\u30a3\u30bf\u30fc\u3092\u4fdd\u5b58\u7d42\u4e86\u3057\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n<h5>\u30b5\u30f3\u30d7\u30eb\u30d7\u30ed\u30b0\u30e9\u30e0\u306e\u5b9f\u884c<\/h5>\n<p style=\"padding-left: 30px;\">\u30fb\u30c7\u30a3\u30b9\u30d7\u30ec\u30a4\u306f\u5fc5\u9808\u3067\u306f\u3042\u308a\u307e\u305b\u3093\u304c\u3001\u30ab\u30e1\u30e9\u306e\u8996\u754c\u306b\u5bfe\u8c61\u7269\u3092\u3057\u3063\u304b\u308a\u5165\u308c\u308b\u305f\u3081\u306b\u306f\u3001\u3042\u3063\u305f\u307b\u3046\u304c\u3088\u3044\u3067\u3059\u3002<\/p>\n<pre class=\"nums:false lang:sh decode:true\">$ python sample_vision1.py<\/pre>\n<p style=\"padding-left: 30px;\">\u30fb\u300c\u3053\u308c\u306a\u3042\u306b\uff1f\u300d\u300c\u3053\u308c\u306a\u3093\u3060\uff1f\u300d\u300c\u3053\u308c\u306f\u4f55\uff1f\u300d\u306a\u3069\u3068\u8a71\u3057\u304b\u3051\u308b\u3068\u3001\u30ed\u30dc\u30c3\u30c8\u304c\u300c\u3069\u308c\u3069\u308c\u300d\u3068\u8a00\u3046\u306e\u3067\u3001\u30ab\u30e1\u30e9\u306e\u524d\u306b\u5bfe\u8c61\u7269\u3092\u63b2\u3052\u3066\u304f\u3060\u3055\u3044\u3002<br \/>\n\u30fb\u6700\u5927\uff13\u3064\u306e\u89e3\u7b54\u5019\u88dc\u304c\u82f1\u8a9e\u3067\u767a\u58f0\u304a\u3088\u3073\u753b\u9762\u306b\u6587\u5b57\u8868\u793a\u3055\u308c\u307e\u3059\u3002<br \/>\n\u30fbCtrl+C\u3067\u7d42\u4e86\u3055\u305b\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n<div align=\"center\"><img decoding=\"async\" src=\"http:\/\/bezelie.com\/blog\/wp-content\/uploads\/2017\/02\/IMG_1946.jpg\" width=\"320\" \/><\/div>\n<h5>\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9<\/h5>\n<pre class=\"lang:python decode:true\">#!\/usr\/bin\/python\n# -*- coding: utf-8 -*-\n# demo Code for Raspberry Pi : Label Recognition of Google Vision API\n\nfrom time import sleep\nimport subprocess\nimport picamera\nimport requests\nimport base64\nimport json\nimport bezelie\n\n# Variables\nGOOGLE_CLOUD_VISION_API_URL = 'https:\/\/vision.googleapis.com\/v1\/images:annotate?key='\nAPI_KEY = ''  # Google Cloud Platform Console\u3067\u767b\u9332\u3057\u305fAPI\u30ad\u30fc\njpgFile = '\/home\/pi\/Pictures\/capture.jpg'  # \u30ad\u30e3\u30d7\u30c1\u30e3\u30fc\u753b\u50cf\u30d5\u30a1\u30a4\u30eb\n\n# Functions\ndef request_cloud_vison_api(image_base64):\n    api_url = GOOGLE_CLOUD_VISION_API_URL + API_KEY\n    req_body = json.dumps({\n        'requests': [{\n            'image': {\n                'content': image_base64.decode('utf-8') # base64\u3067encode\u3059\u308b\u3002\n            },\n            'features': [{\n                'type': 'LABEL_DETECTION',\n#                'type': 'TEXT_DETECTION',\n#                'type': 'LOGO_DETECTION',\n                'maxResults': 3,\n            }]\n        }]\n    })\n    res = requests.post(api_url, data=req_body)\n    return res.json()\n\n# Setting\nbez = bezelie.Control()               # \u3079\u30bc\u30ea\u30fc\u64cd\u4f5c\u30a4\u30f3\u30b9\u30bf\u30f3\u30b9\u306e\u751f\u6210\nbez.moveCenter()                      # \u30b5\u30fc\u30dc\u3092\u30bb\u30f3\u30bf\u30ea\u30f3\u30b0\n\n# Main Loop\ndef main():\n  try:\n    print \"\u30ab\u30e1\u30e9\u306e\u524d\u306b\u4f55\u304b\u3092\u304b\u3056\u3057\u3066\u304f\u3060\u3055\u3044\"\n    with picamera.PiCamera() as camera:\n      camera.resolution = (640, 480)   # Change this number for your display\n      camera.rotation = 180            # comment out if your screen upside down\n      camera.start_preview()\n      sleep(1)\n      while True:\n        print \"--------------------\"\n        camera.stop_preview()\n        camera.capture(jpgFile)\n        sleep(0.1)\n        with open(jpgFile, 'rb') as img:\n          img_byte = img.read()\n        img_base64 = base64.b64encode(img_byte)\n        result = request_cloud_vison_api(img_base64)\n        for i in range(3):\n          try:\n            answer = result['responses'][0]['labelAnnotations'][i]['description'].encode('utf-8')\n            print (answer)\n            subprocess.call('flite -voice \"kal16\" -t \"'+ answer +'\"', shell=True)\n            # Other English Voices :kal awb_time kal16 awb rms slt\n          except:\n            print (\"no answer\")\n        camera.start_preview()\n        sleep (3)\n\n  except KeyboardInterrupt:\n    # CTRL+C\u3067\u7d42\u4e86\n    print \"  \u7d42\u4e86\u3057\u307e\u3057\u305f\"\n\nif __name__ == \"__main__\":\n    main()<\/pre>\n<h5>\u5fdc\u7528<\/h5>\n<p style=\"padding-left: 30px;\">\u30fb[<a href=\"https:\/\/cloud.google.com\/vision\/docs\/requests-and-responses\">\u516c\u5f0f\u30c9\u30ad\u30e5\u30e1\u30f3\u30c8\uff08\u65e5\u672c\u8a9e\uff09<\/a>]<br \/>\n\u30fb\u3053\u306e\u30b5\u30f3\u30d7\u30eb\u3067\u306f\u753b\u50cf\u306b\u6620\u3063\u3066\u3044\u308b\u7269\u306e\u30ab\u30c6\u30b4\u30ea\u30fc\u540d\u3092\u8868\u793a\u3059\u308b\u300cLABEL_DETECTION\u300d\u3068\u3044\u3046\u6a5f\u80fd\u3092\u4f7f\u3063\u3066\u3044\u307e\u3059\u304c\u3001\uff14\uff12\u884c\u76ee\u3042\u305f\u308a\u3067\u30b3\u30e1\u30f3\u30c8\u30a2\u30a6\u30c8\u3057\u3066\u3042\u308b\u300cTEXT_DETECTION\u300d\u300cLOGO_DETECTION\u300d\u3082\u3001\u307b\u307c\u304a\u306a\u3058\u30d7\u30ed\u30b0\u30e9\u30e0\u3067\u4f7f\u3046\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002\u300cTEXT_DETECTION\u300d\u306f\u6587\u5b57\u8a8d\u8b58\uff08OCR\uff09\u3001\u300cLOGO_DETECTION\u300d\u306f\u30ed\u30b4\u8a8d\u8b58\u3067\u3059\u3002<br \/>\n\u30fb\u3053\u306e\u30b5\u30f3\u30d7\u30eb\u3067\u306f\u8a8d\u8b58\u7d50\u679c\u3092\uff13\u3064\u8a00\u308f\u305b\u3066\u3044\u307e\u3059\u304c\u3001\uff11\u3064\u3067\u3044\u3044\u3084\u3068\u3044\u3046\u5834\u5408\u306f\uff17\uff12\u884c\u76ee\u3042\u305f\u308a\u306b\u3042\u308b\u300cfor i in range(3):\u300d\u306e\u6570\u5b57\u3092\uff11\u306b\u3057\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u30fbGoogle\u306f\u69d8\u3005\u306a\u30d7\u30ed\u30b0\u30e9\u30e0\u3092\u5b89\u4fa1\u3067\u63d0\u4f9b\u3057\u3066\u304f\u308c\u3066\u3044\u307e\u3059\u304c\u3001\u3053\u3053\u3067\u306fGoogle Cloud Vision API\u3092\u4f7f\u3063\u3066\u753b\u50cf\u8a8d\u8b58\u3059\u308b\u30ed\u30dc\u30c3\u30c8\u3092\u4f5c\u3063\u3066\u307f\u307e\u3059\u3002 \u30fbVision API\u3092\u4f7f\u3046\u65b9\u6cd5\u306fREST\u65b9\u5f0f\u3068Clou &hellip; <a href=\"http:\/\/bezelie.com\/blog\/?page_id=1999\" class=\"more-link\"><span class=\"screen-reader-text\">&#8220;\u30ab\u30e1\u30e9\u3067\u753b\u50cf\u8a8d\u8b58\u3057\u3066\u307f\u308b&#8221; \u306e<\/span>\u7d9a\u304d\u3092\u8aad\u3080<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-1999","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"http:\/\/bezelie.com\/blog\/index.php?rest_route=\/wp\/v2\/pages\/1999","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/bezelie.com\/blog\/index.php?rest_route=\/wp\/v2\/pages"}],"about":[{"href":"http:\/\/bezelie.com\/blog\/index.php?rest_route=\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"http:\/\/bezelie.com\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/bezelie.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1999"}],"version-history":[{"count":7,"href":"http:\/\/bezelie.com\/blog\/index.php?rest_route=\/wp\/v2\/pages\/1999\/revisions"}],"predecessor-version":[{"id":2328,"href":"http:\/\/bezelie.com\/blog\/index.php?rest_route=\/wp\/v2\/pages\/1999\/revisions\/2328"}],"wp:attachment":[{"href":"http:\/\/bezelie.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1999"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}