How to fix a skewed document photo for OCR in C# .NET Framework
1 min readJan 31, 2020
Skewed photos are the bane of any proper optical character recognition. While easy to fix manually, a computer requires a great deal of training via Deep Learning to manage this effectively on its own. Don’t worry though, there’s a shortcut! Today we will be looking at how to employ an API to get up and running almost instantly.
First we will install the API Client that we need with the Package Manager console:
Install-Package Cloudmersive.APIClient.NET.OCR -Version 2.1.4
Next we must call PreprocessingUnskew using this bit of code:
using System;using System.Diagnostics;using Cloudmersive.APIClient.NET.OCR.Api;using Cloudmersive.APIClient.NET.OCR.Client;using Cloudmersive.APIClient.NET.OCR.Model;namespace Example{public class PreprocessingUnskewExample{public void main(){// Configure API key authorization: ApikeyConfiguration.Default.AddApiKey("Apikey", "YOUR_API_KEY");// Uncomment below to setup prefix (e.g. Bearer) for API key, if needed// Configuration.Default.AddApiKeyPrefix("Apikey", "Bearer");var apiInstance = new PreprocessingApi();var imageFile = new System.IO.Stream(); // System.IO.Stream | Image file to perform OCR on. Common file formats such as PNG, JPEG are supported.try{// Detect and unskew a photo of a documentbyte[] result = apiInstance.PreprocessingUnskew(imageFile);Debug.WriteLine(result);}catch (Exception e){Debug.Print("Exception when calling PreprocessingApi.PreprocessingUnskew: " + e.Message );}}}}
Done!