Playground

PHPでIBMの画像解析を行うAPIを呼び出す

Playground
この記事は約2分で読めます。
スポンサーリンク

以前に画像解析をするLine Botをつくりました

画像解析はIBMが提供しているBluemixのWatson君のVisual Recognitionというものを利用しています

PHPで作成したのですが、色々と戸惑ったため書き留めておきます

 

はじめにプログラムを記載しておきます

サンプルプログラムでは./img/neko.jpgの画像を解析しています

 

スポンサーリンク

結果

string(173) "ash grey color [0.732]
beige color [0.918]
tabby cat [0.5]
domestic cat [0.829]
tiger cat [0.618]
animal [0.992]
mammal [0.992]
carnivore [0.992]
feline [0.992]
cat [0.991]
"

 

個人的に鬼門だったのが画像をPOSTする時です

$path = "./img";
$img = "neko.jpg";
$img_path = $path ."/" .$img;
$cfile = new CURLFile($img_path,'image/jpeg', $img);

CURLFileの使い方を見ると第三引数の中は

CURLFile("test.jpg",'image/jpeg', "MY_FILE");

という書き方が多いです

こうすると拡張子なしの”MY_FILE”というファイル名でwatson君に投げれることになります

ちゃんと拡張子(.jpg)をつけないとエラーを吐きます

コメント

  1. Excеllent way of describing, and good article to obtain facts
    regarding my presntation subjeϲt matter, which i am going to convey
    in university.

    • Thanks.

タイトルとURLをコピーしました