Call Visual Recognition in Watson Java SDK

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");

		//Local upload is also possible
		// ClassifyOptions options = new ClassifyOptions.Builder()
		// .imagesFile(new File("file/662s.jpg "))
		// .build();

		//Specify the image 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("---");
				}
			}
		}


The output result looks like the following.

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

Call Visual Recognition in Watson Java SDK
Java in Visual Studio Code
Investigated how to call services with Watson SDK for Java
Call the super method in Java
Call Java method from JavaScript executed in Java
OCR in Java (character recognition from images)
Call the Windows Notification API in Java
HA/DR support in Couchbase (Java SDK commentary)
[Mac] Install Java in Visual Studio Code
Add --enable-preview option in Java in Visual Studio Code
Partization in Java
Java method call from RPG (method call in own class)
Changes in Java 11
Pi in Java
FizzBuzz in Java
[Mac] Install Java in Visual Studio Code (VS Code)
How to call functions in bulk with Java reflection
Call Amazon Product Advertising API 5.0 (PA-API v5) in Java
Delete All from Java SDK in Azure Cosmos DB
Write a class in Kotlin and call it in Java
Try calling IBM Watson Assistant 2018-07-10 from the Java SDK.
Call a program written in Swift from Processing (Java)
[java] sort in list
Read JSON in Java
Interpreter implementation in Java
Make Blackjack in Java
Call Java from JRuby
Rock-paper-scissors app in Java
Constraint programming in Java
Put java8 in centos7
NVL-ish guy in Java
Combine arrays in Java
Callable Interface in Java
Comments in Java source
Azure functions in java
Format XML in Java
Simple htmlspecialchars in Java
Boyer-Moore implementation in Java
Hello World in Java
Use OpenCV in Java
webApi memorandum in java
Ping commands in Java
Various threads in java
Heapsort implementation (in java)
Zabbix API in Java
ASCII art in Java
Compare Lists in Java
POST JSON in Java
Express failure in Java
JAVA constructor call processing
Create JSON in Java
Date manipulation in Java 8
Use PreparedStatement in Java
What's new in Java 9,10,11
Parallel execution in Java
Initializing HashMap in Java
Call this cat API of Metadata Co., Ltd. in Java.
Get weather forecasts from Watson Weather Company Data in simple Java
Difference in included SDK (Jar) by Java8 type JDK Vender
How to call and use API in Java (Spring Boot)
Append text to BlobItem in Azure BlobStorage SDK Java V8