27
FlashAir Developers Summit FlashAirとCognitive Servicesを使おう! 2017年2月19日 綾瀬 ヒロ Twitter @ayasehiro 2017/2/19 1 All rights reserved. Copyright(C) 2017 AYASE Hiro FlashAir Developers Summit

FlashAirとCognitive Servicesを使おう!

Embed Size (px)

Citation preview

Page 1: FlashAirとCognitive Servicesを使おう!

FlashAir Developers Summit

FlashAirとCognitive Servicesを使おう!

2017年2月19日

綾瀬 ヒロ

Twitter @ayasehiro

2017/2/19 1All rights reserved. Copyright(C) 2017 AYASE Hiro

FlashAir Developers Summit

Page 2: FlashAirとCognitive Servicesを使おう!

FlashAir Developers Summit

1.自己紹介

綾瀬 ヒロ

Twitter:@ayasehiro

FlashAirエバンジェリスト(自称)

2017/2/19 2All rights reserved. Copyright(C) 2017 AYASE Hiro

運輸サービス系インダストリーマネージャです(元鉄道系SE)趣味で庭園鉄道の建設をしていたりします。昔、Mac用フリーソフト「何かon林檎」を作っていました。

Arduino/FlashAir/Xamarin/鉄道模型

Qiita: http://qiita.com/ayasehiroMakersHub: https://makershub.jp/ayasehiro

Page 3: FlashAirとCognitive Servicesを使おう!

FlashAir Developers Summit

2017/2/19All rights reserved. Copyright(C) 2017 AYASE Hiro 3

本発表内容は、個人の見解であり、所属する組織の公式見解ではありません。

Page 4: FlashAirとCognitive Servicesを使おう!

FlashAir Developers Summit

2017/2/19All rights reserved. Copyright(C) 2017 AYASE Hiro 4

作例1) 人物カウンター

Page 5: FlashAirとCognitive Servicesを使おう!

FlashAir Developers Summit

作例1)人物カウンター 全体概要

2017/2/19All rights reserved. Copyright(C) 2017 AYASE Hiro 5

MicrosoftCognitive Services

Face API(顔認識)

人数・年齢・性別を認識

画像ファイル画像ファイル

画像ファイル画像ファイル

画像ファイルの送信

60秒待機

年齢層別・男女別人数カウント

最終更新日時の画像ファイルを検索

60秒周期に写真を撮影

実行スクリプト(Lua)

FlashAir IoT Hubにデータ送信

Page 6: FlashAirとCognitive Servicesを使おう!

FlashAir Developers Summit

Microsoft Cognitive Services

さまざまなAPIが公開されています。 https://www.microsoft.com/cognitive-services/

2016/10/15All rights reserved. Copyright(C) 2016 AYASE Hiro

Page 7: FlashAirとCognitive Servicesを使おう!

FlashAir Developers Summit

Microsoft Cognitive Services

Computer Vision API – 画像分析機能

2017/2/19All rights reserved. Copyright(C) 2017 AYASE Hiro 7

Page 8: FlashAirとCognitive Servicesを使おう!

FlashAir Developers Summit

Microsoft Cognitive Services

Computer Vision API – 画像分析機能(タグ・キャプション等)

2017/2/19All rights reserved. Copyright(C) 2017 AYASE Hiro 8

Page 9: FlashAirとCognitive Servicesを使おう!

FlashAir Developers Summit

Microsoft Cognitive Services Computer Vision API – Describe Image機能

画像データをもとに、タグ(属性)情報とキャプション(説明文)を自動生成する機能。

JPEG, PNG, GIF, BMP形式に対応

4MBまで

50x50ピクセル以上が必要

REST API

Http MethodでPOSTするだけで、JSON形式でタグ・キャプション等の情報を取得できる

無料利用可能

1分間20リクエストまで

1ヵ月5,000リクエストまで

2017/2/19All rights reserved. Copyright(C) 2017 AYASE Hiro 9

Http Method POST

Request URL https://api.projectoxford.ai/vision/v1.0/describe[?maxCandidates]

Request parameters maxCandidates (optional) Maximum number of candidate descriptions to be returned. The default is 1.

Request headers Content-Type (optional) Media type of the body sent to the API.

Ocp-Apim-Subscription-Key Subscription key which provides access to this API. Found in your subscriptions.

Page 10: FlashAirとCognitive Servicesを使おう!

FlashAir Developers Summit

作例1)人物カウンター

Computer Vision API – Faces機能を利用

2017/2/19All rights reserved. Copyright(C) 2017 AYASE Hiro 10

Faces : JSONメッセージ

[ { "age": 28, "gender": "Male", "faceRectangle": { "left": 744, "top": 338, "width": 305, "height": 305 } } ]

Page 11: FlashAirとCognitive Servicesを使おう!

FlashAir Developers Summit

作例1)人物カウンター

Luaスクリプト例

2017/2/19All rights reserved. Copyright(C) 2017 AYASE Hiro 11

boundary = "1234567890"contenttype = "multipart/form-data; boundary=" .. boundarymes = "--" .. boundary .. "¥r¥n"

.."Content-Disposition: form-data; name=¥"file¥"; filename=¥""..last_fname.."¥"¥r¥n"

.."Content-Type: image/jpg¥r¥n¥r¥n"

.."<!--WLANSDFILE-->¥r¥n"

.."--" .. boundary .. "--¥r¥n"

blen = lfs.attributes(last_fpath,"size") + string.len(mes) - 17b, c, h = fa.request{url = "https://westus.api.cognitive.microsoft.com/vision/v1.0/analyze?visualFeatures=Faces",method = "POST",headers = {["Content-Length"] = tostring(blen),["Content-Type"] = contenttype,[“Ocp-Apim-Subscription-Key”] = “ここにサブスクリプションキーを記述する",["maxCandidates"] = "1"},file = last_fpath,body = mes

}

Page 12: FlashAirとCognitive Servicesを使おう!

FlashAir Developers Summit

作例1)人物カウンター

Luaスクリプト例

2017/2/19All rights reserved. Copyright(C) 2017 AYASE Hiro 12

cjson = require "cjson”

if(c == 200) thenres = cjson.decode(b)for idx=1,#res.faces do

local agenum = tonumber(res.faces[idx].age)if(agenum < 20) thenfaces_num_00 = faces_num_00 + 1

elseif(agenum >= 20 and agenum < 60) thenfaces_num_20 = faces_num_20 + 1

elseif(agenum >= 60) thenfaces_num_60 = faces_num_60 + 1

end

if( res.faces[idx].gender == "Female" ) thenfaces_num_female = faces_num_female + 1

elsefaces_num_male = faces_num_male + 1

endend

end

Page 13: FlashAirとCognitive Servicesを使おう!

FlashAir Developers Summit

作例1)人物カウンター

Luaスクリプト例

2017/2/19All rights reserved. Copyright(C) 2017 AYASE Hiro 13

iothub = require("iothub")

iothub.addMeasurement({faces_num_00, faces_num_20, faces_num_60, faces_num_male, faces_num_female

})

Page 14: FlashAirとCognitive Servicesを使おう!

FlashAir Developers Summit

作例1)人物カウンター 詳しくは・・・

Qiitaの記事を参照ください。

http://qiita.com/ayasehiro/items/9651e1231951766fbe12

2017/2/19All rights reserved. Copyright(C) 2017 AYASE Hiro 14

Page 15: FlashAirとCognitive Servicesを使おう!

FlashAir Developers Summit

作例1)人物カウンター 全体概要

2017/2/19All rights reserved. Copyright(C) 2017 AYASE Hiro 15

MicrosoftCognitive Services

Conputer Vision API(顔認識)

人数・年齢・性別を認識

画像ファイル画像ファイル

画像ファイル画像ファイル

画像ファイルの送信

60秒待機

年齢層別・男女別人数カウント

最終更新日時の画像ファイルを検索

60秒周期に写真を撮影

実行スクリプト(Lua)

FlashAir IoT Hubにデータ送信 Azure IoT Hub

Stream Analytics

Azure IoT Hub+Stream Analytics

+Power BIでもできるんだからね!

Page 16: FlashAirとCognitive Servicesを使おう!

FlashAir Developers Summit

2017/2/19All rights reserved. Copyright(C) 2017 AYASE Hiro 16

作例2) 音声で鉄道模型を運転

Page 17: FlashAirとCognitive Servicesを使おう!

FlashAir Developers Summit

iOSアプリpowered by Xamarin

作例2)音声で鉄道模型を運転 全体概要

2017/2/19All rights reserved. Copyright(C) 2017 AYASE Hiro 17

MicrosoftCognitive Services

Bing Speech API(音声認識)

LUIS -Language Understanding

Intelligent Service(自然言語認識)

音 声 録 音

文字列取得・送信

PWM出力ポイント制御

Intent・Entity取得

運転コマンド生成

無線LANモジュール

マイコンボード

モータードライバ

速度八十で前に進め

一番ポイントを右へ

Page 18: FlashAirとCognitive Servicesを使おう!

FlashAir Developers Summit

Microsoft Cognitive Services

さまざまなAPIが公開されています。 https://www.microsoft.com/cognitive-services/

2016/10/15All rights reserved. Copyright(C) 2016 AYASE Hiro

Page 19: FlashAirとCognitive Servicesを使おう!

FlashAir Developers Summit

Microsoft Cognitive Services

Bing Speech API(音声認識) https://www.microsoft.com/cognitive-services/en-us/speech-api

2016/10/15All rights reserved. Copyright(C) 2016 AYASE Hiro

Page 20: FlashAirとCognitive Servicesを使おう!

FlashAir Developers Summit

Microsoft Cognitive Services

Bing Speech API – Speech Recognition機能

音声データをもとに、文字情報を認識する機能。

PCM single channel、Siren、SirenSR形式に対応

REST API

Http MethodでPOSTするだけで、JSON形式で音声認識した文字データを取得できる

無料利用可能

1ヵ月5,000リクエストまで

機能ごとに20リクエスト/分まで

全機能で60リクエスト/分まで

2016/10/15All rights reserved. Copyright(C) 2016 AYASE Hiro

Page 21: FlashAirとCognitive Servicesを使おう!

FlashAir Developers Summit

Microsoft Cognitive Services

Bing Speech API – Speech Recognition機能

対応言語

2016/10/15All rights reserved. Copyright(C) 2016 AYASE Hiro

language-Country

English Name language-Country

English Name language-Country

English Name language-Country

English Name

ar-EG* Arabic (Egypt) en-IN English (India) fr-FR French(France) pt-BR Portuguese(Brazil)

ca-ES Catalan(Spain) en-NZEnglish (New Zealand) it-IT Italian(Italy) pt-PT

Portuguese(Portugal)

da-DK Danish(Denmark) en-USEnglish (United States) ja-JP Japanese(Japan) ru-RU Russian(Russia)

de-DE German(Germany) es-ES Spanish(Spain) ko-KR Korean (Korea) sv-SE Swedish(Sweden)

en-AU English(Australia) es-MX Spanish (Mexico) nb-NONorwegian-Bokmal (Norway)

zh-CN Chinese (China)

en-CA English(Canada) fi-FI Finnish(Finland) nl-NL Dutch(Netherlands) zh-HKChinese (Hong Kong SAR)

en-GBEnglish(United Kingdom) fr-CA French(Canada) pl-PL Polish(Poland) zh-TW Chinese (Taiwan)

*ar-EG supports Modern Standard Arabic (MSA)

Page 22: FlashAirとCognitive Servicesを使おう!

FlashAir Developers Summit

Microsoft Cognitive Services

さまざまなAPIが公開されています。 https://www.microsoft.com/cognitive-services/

2016/10/15All rights reserved. Copyright(C) 2016 AYASE Hiro

Page 23: FlashAirとCognitive Servicesを使おう!

FlashAir Developers Summit

LUIS – Intent設定画面

2017/2/19All rights reserved. Copyright(C) 2017 AYASE Hiro 23

Page 24: FlashAirとCognitive Servicesを使おう!

FlashAir Developers Summit

LUIS – 学習状況確認画面

2017/2/19All rights reserved. Copyright(C) 2017 AYASE Hiro 24

Page 25: FlashAirとCognitive Servicesを使おう!

FlashAir Developers Summit

LUIS – 文章認識例

2017/2/19All rights reserved. Copyright(C) 2017 AYASE Hiro 25

一番ポイントを右へ

速度八十で前に進め

Entityの認識:pointNumber「一番」pointDirection「右」

Intentの認識:ポイント制御用文章と認識

Intentの認識:電車制御用文章と認識

Entityの認識:trainSpeed「八十」trainDirection「前」

Page 26: FlashAirとCognitive Servicesを使おう!

FlashAir Developers Summit

2017/2/19All rights reserved. Copyright(C) 2017 AYASE Hiro 26

というわけで、とても簡単に使えるのでFlashAirでCognitive Servicesを使っていろいろ試してみてください!

Page 27: FlashAirとCognitive Servicesを使おう!

FlashAir Developers Summit

2017/2/19All rights reserved. Copyright(C) 2017 AYASE Hiro 27

ご静聴ありがとうございました