Watson Java SDK で Visual Recognition を呼ぶ
Watson Java SDK
https://github.com/watson-developer-cloud/java-sdk/releases
API Key
https://console.bluemix.net/
VisualRecognition service = new VisualRecognition("2016-05-20");
service.setApiKey("<apikey>");
System.out.println("Classify an image");
// ローカルからのアップロードも可能
// ClassifyOptions options = new ClassifyOptions.Builder()
// .imagesFile(new File("file/662s.jpg"))
// .build();
// 画像URL を指定する
String url = "http://xxx.com/xxx.jpg";
ClassifyOptions options = new ClassifyOptions.Builder() //
.url(url)
.build();
ClassifiedImages result = service.classify(options).execute();
// System.out.println(result);
List<ClassifiedImage> images = result.getImages();
for (ClassifiedImage image : images) {
List<ClassifierResult> cr = image.getClassifiers();
for (ClassifierResult r : cr) {
// System.err.println(r.getName());
List<ClassResult> cc = r.getClasses();
for (ClassResult c : cc) {
// System.err.println("ClassResult : " + c);
System.err.println("ClassName : " + c.getClassName());
System.err.println("Score : " + c.getScore());
System.err.println("TypeHierarchy : " + c.getTypeHierarchy());
System.err.println("---");
}
}
}
出力結果は以下のような感じ。
ClassName : woman at work
Score : 0.654
TypeHierarchy : /person/woman at work
---
ClassName : person
Score : 0.854
TypeHierarchy : null
---
ClassName : pharmacist
Score : 0.599
TypeHierarchy : /person/pharmacist
---
ClassName : bluestocking
Score : 0.595
TypeHierarchy : /person/female/woman/bluestocking
---
ClassName : woman
Score : 0.666
TypeHierarchy : null
---
ClassName : female
Score : 0.667
TypeHierarchy : null
---
ClassName : maiden
Score : 0.5
TypeHierarchy : /person/female/woman/girl/maiden
---
ClassName : girl
Score : 0.516
TypeHierarchy : null
---
ClassName : gray color
Score : 0.96
TypeHierarchy : null
---
Author And Source
この問題について(Watson Java SDK で Visual Recognition を呼ぶ), 我々は、より多くの情報をここで見つけました https://qiita.com/oyahiroki/items/d5a1907ec74c6aaf1b7f著者帰属:元の著者の情報は、元のURLに含まれています。著作権は原作者に属する。
Content is automatically searched and collected through network algorithms . If there is a violation . Please contact us . We will adjust (correct author information ,or delete content ) as soon as possible .