How to Detect Large Text within a Photo using Java

Whether you’re carefully cropping images en-masse to fit a standard size requirement, or you’re simply looking for additional metadata to accompany your image files in storage, it’s good to know exactly where large text is located within an image. You don’t need a complex OCR API to find it, either — you can just use our Large Text Detection API and identify the exact location & size (height/width in terms of pixels) of large, low-density text in any image automatically. The best part: you can use this API for free — all you need to do is register a free account on our website (this will provide an API key with a limit of 800 API calls per month) and use complementary Java code examples provided below to structure your API call.

The first step is to install the API client. So let’s first add a reference to the repository in pom.xml:


And then let’s add a reference to the dependency in pom.xml:


With installation finished, we can call the function, starting by adding our imports to the top of our file & then passing our file path through the imageFile parameter. Once you complete those steps, you’re all set — just remember to include your API key where indicated in the code comments:

// 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)
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 {
TextDetectionResult result = apiInstance.recognizeDetectTextLarge(imageFile);
} catch (ApiException e) {
System.err.println("Exception when calling RecognizeApi#recognizeDetectTextLarge");



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



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