How to fix a skewed document photo in Node.JS with Deep Learning

Original article can be found here (source): Deep Learning on Medium

How to fix a skewed document photo in Node.JS with Deep Learning

In the vast majority of cases, camera photos of documents are skewed to some degree. This skewing can lead to poor results when it comes time to run optical character recognition algorithms. With the power of Deep Learning, this is a problem of the past. We even set the whole time up for you, all you need to do is call in the cavalry.

Install our API client first with npm install, like so:

npm install cloudmersive-ocr-api-client --save

Now call the preprocessingUnskew function as you see below.

var CloudmersiveOcrApiClient = require('cloudmersive-ocr-api-client');var defaultClient = CloudmersiveOcrApiClient.ApiClient.instance;// Configure API key authorization: Apikeyvar Apikey = defaultClient.authentications['Apikey'];Apikey.apiKey = 'YOUR API KEY';// Uncomment the following line to set a prefix for the API key, e.g. "Token" (defaults to null)//Apikey.apiKeyPrefix = 'Token';var apiInstance = new CloudmersiveOcrApiClient.PreprocessingApi();var imageFile = "/path/to/file"; // File | Image file to perform OCR on. Common file formats such as PNG, JPEG are supported.var callback = function(error, data, response) {if (error) {console.error(error);} else {console.log('API called successfully. Returned data: ' + data);}};apiInstance.preprocessingUnskew(imageFile, callback);

Easy. After a moment or two of processing, the API will kick back the resulting image, with all of the text un-skewed. OCR time!