LoginSignup
4
3

More than 5 years have passed since last update.

PepperからWatson Visual Recognitionを呼ぶ

Posted at

この記事はペッパソンの最中に書いているメモです。

Watson Visual Recognition のAPIリファレンスはこちら
APIリファレンス https://www.ibm.com/watson/developercloud/visual-recognition/api/v3/?curl#introduction

Watson Visual RecognitionをPepperから呼ぶ場合、Pythonのモジュール watson-developer-cloud をPepperに入れるのは依存関係の問題で大変なので、エンドポイントを直接呼びたい。で、ドキュメントのcURLのサンプルを参考に、PepperのPythonボックス内で、requestsモジュールを使って

import requests
api_key = self.getParameter("api_key")
url = "https://gateway-a.watsonplatform.net/visual-recognition/api/v3/classifiers?api_key=%s&version=2016-05-20" % api_key
res = requests.get(url)

ってやったら落ちてしまってハマりました。
ちなみに、上記コードはjupyter notebookだと動きます。

で、どうするかというと、Node-redにご登場いただきます。
そもそも上の「分類器一覧取得」は Watson Visual Recognition Utilっていうノードで取れるのですが、敢えてhttp requests ノードを使って、
以下のような簡単なフローを書くと、ちゃんと取れるようになります。
スクリーンショット 2017-09-23 20.25.41.png

[{"id":"48072e51.0a369","type":"http in","z":"6675f4be.253fac","name":"","url":"/getClass","method":"get","upload":false,"swaggerDoc":"","x":104.5,"y":231,"wires":[["5f0b2d0a.5f86f4"]]},{"id":"eb2a569b.9e94d8","type":"http response","z":"6675f4be.253fac","name":"","statusCode":"","headers":{},"x":435.5,"y":232,"wires":[]},{"id":"5f0b2d0a.5f86f4","type":"http request","z":"6675f4be.253fac","name":"","method":"GET","ret":"obj","url":"https://gateway-a.watsonplatform.net/visual-recognition/api/v3/classifiers?api_key=<YOUR_API_KEY>&version=2016-05-20","tls":"","x":284.5,"y":233,"wires":[["eb2a569b.9e94d8"]]}]

ハマったのでメモ

4
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
3