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");
//Le téléchargement local est également possible
// ClassifyOptions options = new ClassifyOptions.Builder()
// .imagesFile(new File("file/662s.jpg "))
// .build();
//Spécifiez l'URL de l'image
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("---");
}
}
}
Le résultat de sortie ressemble à ce qui suit.
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 ---
Recommended Posts