Visual Recognitionで識別してみる | Watson API

Windows 環境において、実際にイメージファイルをアップロードし 画像認識 (Visual Recognition) する手順の紹介です。
以下はWindows コマンドプロンプトよりローカルに存在するファイルをアップロードしてイメージ識別する手順です。

APIKEYは bluemix サービスより資格情報を確認することにより取得してください。なお、他のサービスと異なり、このサービスはユーザ名とパスワードは使用しないようです。ここではc:\temp\orange.jpgを識別しています。環境に合わせて変更してください。

スポンサーリンク

C:\>set APIURL=https://gateway-a.watsonplatform.net/visual-recognition/api
C:\>set APIKEY=****************************************

C:\>curl -k -X POST -F "images_file=@c:\temp\orange.jpg" "%APIURL%/v3/classify?api_key=%APIKEY%&version=2016-05-20"

スポンサーリンク

みかんの画像を認識させてみます。


citrus(柑橘系) 0.945 とかなり正確に認識しています。

スポンサーリンク

{
"custom_classes": 0,
"images": [
{
"classifiers": [
{
"classes": [
{
"class": "clementine",
"score": 0.737,
"type_hierarchy": "/plant/tree/citrus/clementine"
},
{
"class": "citrus",
"score": 0.945
},
{
"class": "tree",
"score": 0.836
},
{
"class": "plant",
"score": 0.836
},
{
"class": "mandarin",
"score": 0.649,
"type_hierarchy": "/fruit/citrus/mandarin"
},
{
"class": "fruit",
"score": 0.81
},
{
"class": "tangerine",
"score": 0.607,
"type_hierarchy": "/fruit/citrus/tangerine"
},
{
"class": "satsuma",
"score": 0.554,
"type_hierarchy": "/plant/tree/citrus/satsuma"
},
{
"class": "orange color",
"score": 1.0
}
],
"classifier_id": "default",
"name": "default"
}
],
"image": "orange.jpg"
}
],
"images_processed": 1
}

次はジャガイモを認識させてみます。

potato(じゃがいも)0.594とそこそこ正しく認識されています。背景色を考慮したり、もっと芽の出た素材を使用すればさらに高度な認識率になった可能性もあります。

{
"custom_classes": 0,
"images": [
{
"classifiers": [
{
"classes": [
{
"class": "earthball",
"score": 0.596,
"type_hierarchy": "/fungus/earthball"
},
{
"class": "fungus",
"score": 0.674
},
{
"class": "potato",
"score": 0.594,
"type_hierarchy": "/root vegetable/potato"
},
{
"class": "root vegetable",
"score": 0.624
},
{
"class": "vegetable",
"score": 0.624
},
{
"class": "giant puffball",
"score": 0.58,
"type_hierarchy": "/fungus/giant puffball"
},
{
"class": "earthenware jar",
"score": 0.557
},
{
"class": "jar",
"score": 0.603
},
{
"class": "gourd",
"score": 0.554,
"type_hierarchy": "/bottle/gourd"
},
{
"class": "bottle",
"score": 0.554
},
{
"class": "alabaster color",
"score": 1.0
}
],
"classifier_id": "default",
"name": "default"
}
],
"image": "potato.jpg"
}
],
"images_processed": 1
}

次はトマトです。

tomato(トマト) 0.737 とそこそこ正しく認識されています。ところで"beefsteak tomato"とは何でしょうか?こちらの方が数値が高いです。

{
"custom_classes": 0,
"images": [
{
"classifiers": [
{
"classes": [
{
"class": "beefsteak tomato",
"score": 0.877,
"type_hierarchy": "/vegetable/beefsteak tomato"
},
{
"class": "vegetable",
"score": 0.966
},
{
"class": "tomato",
"score": 0.737,
"type_hierarchy": "/vegetable/tomato"
},
{
"class": "dark red color",
"score": 0.879
},
{
"class": "reddish orange color",
"score": 0.633
}
],
"classifier_id": "default",
"name": "default"
}
],
"image": "tomato.jpg"
}
],
"images_processed": 1
}

最後は玉ねぎです。

残念。色が悪かったのか、玉ねぎとは認識されませんでした。パンあるいは動物と認識されたようです。

{
"custom_classes": 0,
"images": [
{
"classifiers": [
{
"classes": [
{
"class": "bagel",
"score": 0.872,
"type_hierarchy": "/food product/bread/bun/bagel"
},
{
"class": "bun",
"score": 0.872
},
{
"class": "bread",
"score": 0.872
},
{
"class": "food product",
"score": 0.872
},
{
"class": "food",
"score": 0.872
},
{
"class": "paper nautilus (animal with shell)",
"score": 0.554,
"type_hierarchy": "/invertebrate/shellfish /paper nautilus (animal with shell)"
},
{
"class": "shellfish ",
"score": 0.558
},
{
"class": "invertebrate",
"score": 0.565
},
{
"class": "animal",
"score": 0.565
},
{
"class": "chestnut color",
"score": 0.993
}
],
"classifier_id": "default",
"name": "default"
}
],
"image": "onion.jpg"
}
],
"images_processed": 1
}

[Visual Recognitionに戻る]