Find Duplicate Images Introduction
This article explains how to find duplicate images. First, you will upload a group of images to Cloud Storage and then use the API to find duplicate images.
The API URL is: GET /imaging/ai/imageSearch/{searchContextId}/findDuplicates
Resource URI
Swagger UI lets you call Aspose.Imaging REST APIs directly from the browser. The description of the APIs and their parameters are also given there.
cURL Example
SDKs
Using an SDK (API client) is the quickest way for a developer to speed up the development. An SDK takes care of a lot of low-level details of making requests and handling responses and lets you focus on writing code specific to your particular project. Check out our GitHub repository for a complete list of Aspose.Imaging SDKs along with working examples, to get you started in no time.
SDK Examples
.NET
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-imaging-cloud/aspose-imaging-cloud-dotnet
public void FindImageDuplicates()
{
// Create new search context
string searchContextId = this.CreateImageSearch();
// Upload input images to Cloud Storage
string[] images = { ComparableImage, ComparingImageSimilarLess15, ComparingImageSimilarMore75 };
foreach (string imageName in images)
{
// Upload local image to Cloud Storage
using (FileStream localInputImage = File.OpenRead(ImagingBase.PathToDataFiles + imageName))
{
var uploadFileRequest = new UploadFileRequest(imageName, localInputImage);
FilesUploadResult result = this.ImagingApi.UploadFile(uploadFileRequest);
}
}
this.CreateImageFeatures(ComparableImage, false, searchContextId);
this.CreateImageFeatures(ComparingImageSimilarLess15, false, searchContextId);
this.CreateImageFeatures(ComparingImageSimilarMore75, false, searchContextId);
double? similarityThreshold = 80; // The similarity threshold
string folder = null; // Path to input files
string storage = null; // We are using default Cloud Storage
ImageDuplicatesSet imageDuplicatesSet = this.ImagingApi.FindImageDuplicates(
new FindImageDuplicatesRequest(searchContextId, similarityThreshold, folder, storage));
Console.WriteLine("Duplicates Count: " + imageDuplicatesSet.Duplicates.Count);
// Delete the search context
this.DeleteImageSearch(searchContextId);
}
Java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
String APP_KEY = ""; // Get AppKey and AppSID from https:dashboard.aspose.cloud/
String APP_SID = ""; // Get AppKey and AppSID from https:dashboard.aspose.cloud/
String DATA_PATH = "src/main/resources/";
ImagingApi imagingApi = new ImagingApi(APP_KEY, APP_SID);
try {
String searchContextId = "5728a4ed-12bb-4b4a-8dce-38295735549f";
Double similarityThreshold = 90.0;
String folder = null; // Folder with image to process
String storage = null; // We are using default Cloud Storage
ImageDuplicatesSet result = imagingApi.getSearchContextFindDuplicates(
new GetSearchContextFindDuplicatesRequest(searchContextId, similarityThreshold, folder, storage));
for (ImageDuplicates duplicates : result.getDuplicates())
{
System.out.println("Duplicates:");
for (SearchResult duplicate : duplicates.getDuplicateImages())
{
System.out.println("ImageName: " + duplicate.getImageId() +
", Similarity: " + duplicate.getSimilarity());
}
}
} catch (Exception e) {
System.out.println(e.getMessage());
}