How to get the angle of a document page photo in C# .NET Framework

Cloudmersive
2 min readJan 31, 2020

--

Proper alignment is a crucial step in preprocessing a document photo for optical character recognition. To achieve this, we will need to angle of our document relative to the photo. Without digging into the ant’s nest that is Deep Learning, we will instead be taking a shortcut today — one that will have us up and running in just a few short minutes. Let’s dive right in.

To start, we will need to install our API Client via NuGet. Enter this command into the Package Manager console:

Install-Package Cloudmersive.APIClient.NET.OCR -Version 2.1.4

Now call PreprocessingGetPageAngle:

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 PreprocessingGetPageAngleExample{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{// Get the angle of the page / document / receiptGetPageAngleResult result = apiInstance.PreprocessingGetPageAngle(imageFile);Debug.WriteLine(result);}catch (Exception e){Debug.Print("Exception when calling PreprocessingApi.PreprocessingGetPageAngle: " + e.Message );}}}}

Annnnd we’re done! No seriously, that’s all there is to it. We can use this angle for rotating the image back into alignment so that OCR can commence.

--

--

Cloudmersive
Cloudmersive

Written by Cloudmersive

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

No responses yet