Image Processing API: Compare two Images for Similarity with Java

Sometimes two images can look kind of similar, but it’s hard to tell how similar they really are. Our Image comparison API takes care of that problem, using deep learning to generate an Image Similarity score between 0.0 and 1.0 (higher values indicate greater similarity; 1.0 means the images are identical).

Following steps below, you can easily implement this API into your project with Java.

Get started by installing the Java SDK with Maven. Add a reference to the repository in pom.xml:

<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>

Then add one 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 more step and you’re done — add in the import classes, then call the image processing 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 baseImage = new File("/path/to/inputfile"); // File | Image file to compare against. Common file formats such as PNG, JPEG are supported.
File comparisonImage = new File("/path/to/inputfile"); // File | Image to compare to the base image.
String recognitionMode = "recognitionMode_example"; // String | Optional, specify the recognition mode; possible values are Normal, Basic and Advanced. Default is Normal.
try {
byte[] result = apiInstance.recognizeSimilarityCompare(baseImage, comparisonImage, recognitionMode);
System.out.println(result);
} catch (ApiException e) {
System.err.println("Exception when calling RecognizeApi#recognizeSimilarityCompare");
e.printStackTrace();
}

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Cloudmersive

Cloudmersive

437 Followers

There’s an API for that. Cloudmersive is a leader in Highly Scalable Cloud APIs.