OCR Preprocessing API: Detect and Unskew a Photo of a Document with JavaScript

Photos taken with cell phone cameras are prone to becoming skewed. That isn’t a big deal –unless you’re thinking of performing an OCR operation on that photo, or trying to convert it into a PDF. To accomplish either of those operations quickly and cleanly, you should take advantage of our Unskew OCR Preprocessing API, which will turn a skewed image into a perfectly square image. You can then perform OCR directly on the photo or convert to PDF first and then use that document in a suitable OCR operation instead.

Connecting to this API is easy — below, we’ve provided instructions to include ready-to-run code snippets for structuring your API call with JavaScript. On the Cloudmersive API Console page, you’ll find similar code snippets available in a dozen of the most commonly used programming languages.

Let’s start by installing the jQuery library, which we can do by running the below command:

bower install jquery

Then we can add in a code snippet which will capture the image file for the operation:

var form = new FormData();
form.append("imageFile", fileInput.files[0], "file");

Now there’s only one step left — add in the below code for the API call, and you’re all done:

var settings = {
"url": "https://api.cloudmersive.com/ocr/preprocessing/image/unskew",
"method": "POST",
"timeout": 0,
"headers": {
"Content-Type": "multipart/form-data",
"Apikey": "YOUR-API-KEY-HERE"
},
"processData": false,
"mimeType": "multipart/form-data",
"contentType": false,
"data": form
};
$.ajax(settings).done(function (response) {
console.log(response);
});

You’ll need to include your Cloudmersive API key where indicated in the code above. To get a key, head to our website (Home — Cloudmersive APIs) and create a free account. With your free account, you’ll get a limit of 800 API calls per month, with access to dozens of similar Cloudmersive utility APIs.

--

--

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
Cloudmersive

Cloudmersive

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