Image Recognition API: Describe an Image in Natural Language using Java
Did you know there’s an easy way to quickly describe photos… without even looking at them? That’s what our Image Recognition & Description API can do for you. All you need to do is input your image (common file formats like JPEG, PNG accepted), call the function, and you’ll receive a freshly generated English Language text description based on analysis of the image’s contents.
Taking advantage of this API is easy — we provide ready-to-run code in many of the most common programming languages to ensure an easy custom code connection. Below, you can follow steps to use this API with complimentary code snippets in Java.
Start by installing the Java SDK (instructions included in this article for Maven; for instructions to use Gradle, visit the Cloudmersive API Console). Add a reference to the pom.xml repository:
<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>
Then add a reference to the dependency in pom.xml:
<dependencies>
<dependency>
<groupId>com.github.Cloudmersive</groupId>
<artifactId>Cloudmersive.APIClient.Java</artifactId>
<version>v4.25</version>
</dependency>
</dependencies>
One final step and you’re all done: just add in the import classes and call the function:
// Import classes:
//import com.cloudmersive.client.invoker.ApiClient;
//import com.cloudmersive.client.invoker.ApiException;
//import com.cloudmersive.client.invoker.Configuration;
//import com.cloudmersive.client.invoker.auth.*;
//import com.cloudmersive.client.RecognizeApi;ApiClient defaultClient = Configuration.getDefaultApiClient();// Configure API key authorization: Apikey
ApiKeyAuth Apikey = (ApiKeyAuth) defaultClient.getAuthentication("Apikey");
Apikey.setApiKey("YOUR API KEY");
// Uncomment the following line to set a prefix for the API key, e.g. "Token" (defaults to null)
//Apikey.setApiKeyPrefix("Token");RecognizeApi apiInstance = new RecognizeApi();
File imageFile = new File("/path/to/inputfile"); // File | Image file to perform the operation on. Common file formats such as PNG, JPEG are supported.
try {
ImageDescriptionResponse result = apiInstance.recognizeDescribe(imageFile);
System.out.println(result);
} catch (ApiException e) {
System.err.println("Exception when calling RecognizeApi#recognizeDescribe");
e.printStackTrace();
}
To run the function, you’ll need a Cloudmersive API key, which you can obtain easily & for free by visiting our website (Home — Cloudmersive APIs) and creating a free account.