How to get the angle of a document page photo in Java

Cloudmersive
2 min readJan 24, 2020

--

Optical character recognition (OCR) is a perfect example of technology taking the grunt work out of everyday tasks, allowing us to automatically convert a photograph into text. For optimal results with OCR, adjusting the image is often crucial. Today we will be looking at how to find the angle a document is being viewed from, which can then be used for image adjustment.

We will start by dynamically compiling our library using Jitpack. This will require our Maven POM file to have the following references:

Repository.

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

Dependency.

<dependencies>
<dependency>
<groupId>com.github.Cloudmersive</groupId>
<artifactId>Cloudmersive.APIClient.Java</artifactId>
<version>v2.75</version>
</dependency>
</dependencies>

Next, we simply have to call preprocessingGetPageAngle, as you can see below:

// 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: ApikeyApiKeyAuth 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");PreprocessingApi apiInstance = new PreprocessingApi();File imageFile = new File("/path/to/file"); // File | Image file to perform OCR on.  Common file formats such as PNG, JPEG are supported.try {GetPageAngleResult result = apiInstance.preprocessingGetPageAngle(imageFile);System.out.println(result);} catch (ApiException e) {System.err.println("Exception when calling PreprocessingApi#preprocessingGetPageAngle");e.printStackTrace();}

Done!

--

--

Cloudmersive
Cloudmersive

Written by Cloudmersive

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

No responses yet