OCR Preprocessing: Detect and Unrotate a Document Image using Java

Tired of manually un-skewing documents for OCR? You’ve come to the right place. Our Unrotate API will detect the angle of a skewed document and automatically correct it, making the next OCR operation easy to accomplish. You can easily take advantage of this API using ready-to-run code provided in Java below.

Start with Java SDK installation. Add a reference to the repository in pom.xml:


Next, add one to the dependency in pom.xml:


Lastly, add in the import classes and call the OCR 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.PreprocessingApi;
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)
PreprocessingApi apiInstance = new PreprocessingApi();
File imageFile = new File("/path/to/inputfile"); // File | Image file to perform OCR on. Common file formats such as PNG, JPEG are supported.
try {
byte[] result = apiInstance.preprocessingUnrotate(imageFile);
} catch (ApiException e) {
System.err.println("Exception when calling PreprocessingApi#preprocessingUnrotate");




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

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Coding Journal: entry 1.0

Dynamic Input Width React Component

When do you need Flux library, explained with Car as example.

Building a reusable Component System with React.js and styled-components

Node.js and Express.js with env variable

Creating a native animated driver for react-native-web: Traversing the graph and animating

Echo Ridge Lot 84, Siding Done, Masonry Next

Echo Ridge Lot 84, Siding Done, Masonry Next

Creating Adminlte vue components part 1. Designing API component

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.

More from Medium

OpenCV in SpringBoot Application

Convert a Photo of a Document into Text using Java

How to Perform Hate Speech Analysis & Detection on Text using Java

Get Proper Nouns in a String using Java: NLP API