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:
<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>
Next, 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>
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)
//Apikey.setApiKeyPrefix("Token");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);
System.out.println(result);
} catch (ApiException e) {
System.err.println("Exception when calling PreprocessingApi#preprocessingUnrotate");
e.printStackTrace();
}