IBM Bluemix AlchemyAPI 1
Alchemy API 2
Free API Key h"p://www.alchemyapi.com/ 3
目的 チェック ( 例 )To retrieve meta informa7on in images. 名 姓 メールアドレス確認メールアドレス 挑戦すること 4
Free API Key!! 1000! API API! API =! API API 5
API Key 6
7
ちなみに IBM では 人 工知能 (AI) とは 言いません コグニティブ (Cogni.ve 認識識型 人 工知能 ) と 言います ( ) AI 8 AlchemyAPI Watson
Alchemy Vision Alchemy Face Detec7on 結果のフォーマット 各配列要素の中身 9
URL Alchemy Vision Alchemy Face Detect API 10
AlchemyVision h"p://www.alchemyapi.com/products/demo/alchemyvision Top Page >> Products >> Demo >> AlchemyVision Demo 11
Alchemy Vision API URL URL Get http://access.alchemyapi.com/calls/url/urlgetrankedimagekeywords?apikey= API &url= URL &outputmode=json &knowledgegraph=1 12
URLGetRankedImageKeywords API { "status": "OK", "usage": "By accessing AlchemyAPI or ", "url": "h<p://xxx.com/wp- content/uploads/2015/05/aaaa.jpg", "totaltransacjons": 4", この API コールで消費したトランザクションは 4 "imagekeywords": [ 結果は imagekeywords の中 ( 配列 ) { text": sport", "score": "0.989013 sport の確率が 98.9013% と認識 }, { text": football", football の確率が 98.5226% と認識 "score": "0.985226 } ] } API http://www.alchemyapi.com/api/image-tagging/urls.html 13
API 14 h"p://www.alchemyapi.com/api/image- tagging/urls.html Top Page >> Developers >> Documenta7ons >> Image Tagging >> API Calls >> Web API
URL http://access.alchemyapi.com/calls/url/urlgetrankedimagekeywords?apikey= API Key &outputmode=json &url= URL 15
Alchemy Face Detection 16 h"p://www.alchemyapi.com/products/demo/face- detec7on Top Page >> Products >> Demo >> AlchemyVision Face API Demo
Alchemy Face Detection API URL URL Get http://access.alchemyapi.com/calls/url/urlgetrankedimagefacetags?apikey= API &url= URL &outputmode=json &knowledgegraph=1 17
URLGetRankedImageFaceTags API { "status": "OK", "usage": "By accessing AlchemyAPI or ", "url": "h"p://xxx.com/wp- content/uploads/2015/05/aaaa.jpg", "totaltransac7ons": "5", "imagefaces": [ { age : { "agerange": "18-24", "score": "0.702753 }, "gender": { "gender": "FEMALE", "score": "0.991837 }, "iden7ty": { "knowledgegraph": { "typehierarchy": "/people/ariana grande }, ] } "name": "Ariana Grande", "score": "0.622459" }, "posi7onx": "116", "posi7ony": "19", height : 48, "width": "48 } この API コールで消費したトランザクションは 5 結果は imagefaces の中 ( 配列 ) age: 推定年齢層と その確度 gender: 推定性別と その確度 個人が特定できた場合は iden7ty 内に情報が入り 名前とその確度 posi7onx, posi7ony: 顔の位置 width, height: 顔のサイズ API http://www.alchemyapi.com/api/face-detection/urls.html 18
API 19 h"p://www.alchemyapi.com/api/face- detec7on/urls.html Top Page >> Developers >> Documenta7ons >> Face Detec7on >> API Calls >> Web API
URL http://access.alchemyapi.com/calls/url/urlgetrankedimagefacetags?apikey= API Key &outputmode=json &url= URL 20
URL 21
URL Alchemy Vision Alchemy Face Detect API 22
Bluemix 23
WEB WEB 24
PHP PHP PHP 25
PHP 26
PHP kkimura -php-yyyymmdd 27
30 秒 ~ 1 分 PHP PHP 28
29
PHP 30
PHP PHP 31
(1) PHP URL ***.php?url=http://xxxxxxxx/xxx.jpg (2) URL Alchemy Vision API Alchemy Face Detection API (3) JSON (4) 32
Bluemix 1. Eclipse Eclipse 2. cf 3. IDS(IBM DevOps Services) Git 今回は cf ツールを使った方法を紹介します 33
cf https://github.com/cloudfoundry/cli#downloads Stable Installers Google Github cf 34
cf OS X cf v Mac >> 35
PHP c:\tmp\docroot 36
> cd \tmp\docroot 37
cf cf Bluemix > cf login a https://api.ng.bluemix.net/ cf Bluemix Login Bluemix PHP Space Login Error 38
PHP PHP > notepad image.php 39
image.php (1) <html> <head> <title>alchemyapi </title> </head> <body> <?php $trans1 = 0; $trans2 = 0; $trans1 = $json1->totaltransactions; $imagekeywords = $json1->imagekeywords; if( count( $imagekeywords ) ){?> <h2>keywords</h2> <table border='1'> <tr><th>text</th><th>score</th></tr> <?php 配列の結果をループで 1 つずつ取り出す if( isset( $_GET['url'] ) ){ $apikey = Alchemy API Key '; API key の値 for( $i = 0; $i < count( $imagekeywords ); $i ++ ){ $imagekeyword = $imagekeywords[$i]; $url = $_GET['url']; 画像 URL を取得 $alchemyurl = 'http://access.alchemyapi.com/calls/url/';?> $text = $imagekeyword->text; $score = $imagekeyword->score;?> <img src='<?php echo $url;?>'/> <p/> <tr><td><?php echo $text;?></td><td><?php echo $score;?></td></tr> <?php } 40 <?php $apiurl1 = $alchemyurl. 'URLGetRankedImageKeywords? apikey='. $apikey. '&outputmode=json&url='. urlencode( $url ); $text1 = file_get_contents( $apiurl1 ); $json1 = json_decode( $text1 ); モノ認識 API の URL?> </table> <p/> <?php API を実行して 結果の JSON を取り出す }
41 image.php (2) $apiurl2 = $alchemyurl. 'URLGetRankedImageFaceTags? apikey='. $apikey. '&outputmode=json&knowledgegraph=1&url='. urlencode( $url ); $text2 = file_get_contents( $apiurl2 ); $json2 = json_decode( $text2 ); $trans2 = $json2->totaltransactions; $imagefaces = $json2->imagefaces; if( count( $imagefaces ) ){?> <h2>facetags</h2> <table border='1'> <tr><th>attr</th><th>value</th><th>score</th></tr> <?php for( $i = 0; $i < count( $imagefaces ); $i ++ ){ $imageface = $imagefaces[$i]; $positionx = $imageface->positionx; $positiony = $imageface->positiony; $width = $imageface->width; $height = $imageface->height; $ageo = $imageface->age; $agerange = $ageo->agerange; $agescore = $ageo->score; 顔認識 API の URL API を実行して 結果の JSON を取り出す 配列の結果をループで 1 つずつ取り出す $gendero = $imageface->gender; $gender = $gendero->gender; $genderscore = $gendero->score;?> <tr><th colspan='3'><?php echo $i;?></th></tr> <tr><td>positionx</td><td><?php echo $positionx;?></td><td> </td></tr> <tr><td>positiony</td><td><?php echo $positiony;?></td><td> </td></tr> <tr><td>width</td><td><?php echo $width;?></td><td> </td></tr> <tr><td>height</td><td><?php echo $height;?></td><td> </td></tr> <tr><td>age</td><td><?php echo $agerange;?></td><td><?php echo $agescore;?></td></tr> <tr><td>gender</td><td><?php echo $gender;?></td><td><?php echo $genderscore;?></td></tr> <?php $identityo = $imageface->identity; if( $identityo ){ $name = $identityo->name; $namescore = $identityo->score;?> <tr><td>name</td><td><?php echo $name;?></td><td><?php echo $namescore;?></td></tr>
image.php (3) <?php }?> <?php }?> </table> <p/> <?php }?> <div align='right'> <?php echo $trans1;?> + <?php echo $trans2;?> = <?php echo ($trans1 + $trans2);?> </div> <?php }?> </body> </html> 42
! https://github.com/dotnsf/alchemyapi_php_sample! jqcloud https://github.com/lucaong/jqcloud *.php, *.js, *.css image.php, index.php jqcloud.css, jqcloud-1.0.4.js image.php, index.php apikey API Key 43
PHP 30 秒 ~ 1 分 Bluemix PHP > cf push Blumix PHP 44
PHP 45
image.php URL http://.mybluemix.net/image.php?url= URL 46
index.php URL http://.mybluemix.net/?url= URL 47
!! URL ImageGetRankedImageKeywords API ImageGetRankedImageFaceTags API 48