Hands-on Session: .NET Client Library for Cloud OCR SDK

Demo: Implementation of Document Archiving Scenario

  1. Image processing with processImage method
  2. Processing parameters:
    1. Processing profile = documentArchiving
    2. Recognition languages = English, German
    3. Export format = searchable PDF
    4. Optional settings:
      1. Preprocessing: Correct orientation, correct skew, image source
      2. Text types
      3. Tagged PDF

Result of the Demo: Document Archiving Scenario - ProcessImage

Result of the Demo: Document Archiving Scenario - ProcessImage

// Copyright © 2019 ABBYY Production LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
 
using Abbyy.CloudSdk.V2.Client.Models;
using Abbyy.CloudSdk.V2.Client.Models.Enums;
using Abbyy.CloudSdk.V2.Client.Models.RequestParams;
using System;
using System.Collections.Generic;
using System.IO;
using System.Threading.Tasks;
 
namespace Abbyy.CloudSdk.V2.Client.Sample
{
	public class Program
	{
		private const string ApplicationId = "Enter APP ID";
		private const string Password = "Enter PWD";
		private const string FilePath = "Image_letter_1.tif";
 
		/// <summary>
		/// Processing Location URL https://www.ocrsdk.com/documentation/specifications/data-processing-location/
		/// </summary>
		private const string ServiceUrl = "https://cloud-westus.ocrsdk.com";
 
		private static AuthInfo _authInfo;
 
		public static async Task Main()
		{
			_authInfo = new AuthInfo
			{
				Host = ServiceUrl,
				ApplicationId = ApplicationId,
				Password = Password,
			};
 
			var resultUrls = await ProcessImageAsync();
 
 
			foreach (var resultUrl in resultUrls)
			{
				Console.WriteLine(resultUrl);
			}
		}
 
		private static async Task<List<string>> ProcessImageAsync()
		{
			var imageParams = new ImageProcessingParams
			{
				Profile = ProcessingProfile.DocumentArchiving,
				Language = "English, German",
                                ExportFormats = new[] { ExportFormat.Txt, ExportFormat.PdfSearchable },
 
				//TextTypes = new[] { TextType.Normal, TextType.Index },
				//CorrectOrientation = false,
				//CorrectSkew = false,
				//ImageSource = ImageSource.Scanner,
				//WriteTags = WriteTags.Write,
 
 
			};
 
			using (var client = new OcrClient(_authInfo))
			using (var fileStream = new FileStream(FilePath, FileMode.Open))
			{
				var taskInfo = await client.ProcessImageAsync(
					imageParams,
					fileStream,
					Path.GetFileName(FilePath),
					waitTaskFinished: true);
 
				return taskInfo.ResultUrls;
			}
		}
	}
}

Result of the Demo: Document Archiving Scenario - ProcessDocument

Result of the Demo: Document Archiving Scenario - ProcessDocument

// Copyright © 2019 ABBYY Production LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
 
using Abbyy.CloudSdk.V2.Client.Models;
using Abbyy.CloudSdk.V2.Client.Models.Enums;
using Abbyy.CloudSdk.V2.Client.Models.RequestParams;
using System;
using System.Collections.Generic;
using System.IO;
using System.Threading.Tasks;
 
namespace Abbyy.CloudSdk.V2.Client.Sample
{
	public class Program
	{
		private const string ApplicationId = "Enter APP ID";
		private const string Password = "Enter PWD";
 
		/// <summary>
		/// Processing Location URL https://www.ocrsdk.com/documentation/specifications/data-processing-location/
		/// </summary>
		private const string ServiceUrl = "https://cloud-westus.ocrsdk.com";
 
		private static AuthInfo _authInfo;
 
		public static async Task Main()
		{
			_authInfo = new AuthInfo
			{
				Host = ServiceUrl,
				ApplicationId = ApplicationId,
				Password = Password,
			};
 
			var ocrClient = new OcrClient(_authInfo);
 
			var resultUrls = await ProcessDocumentAsync(ocrClient);
 
			foreach (var resultUrl in resultUrls)
			{
				Console.WriteLine(resultUrl);
			}
		}
 
		private static async Task<List<string>> ProcessDocumentAsync(IOcrClient ocrClient)
		{
			Guid taskId = await UploadFilesAsync(ocrClient);
 
			var processingParams = new DocumentProcessingParams
			{
				Profile = ProcessingProfile.DocumentArchiving,
				Language = "English, German",
                                ExportFormats = new[] { ExportFormat.Txt, ExportFormat.PdfSearchable },
 
				//TextTypes = new[] { TextType.Normal, TextType.Index },
				//CorrectOrientation = false,
				//CorrectSkew = false,
				//ImageSource = ImageSource.Scanner,
				//WriteTags = WriteTags.Write,
				TaskId = taskId,
			};
 
			var taskInfo = await ocrClient.ProcessDocumentAsync(processingParams, waitTaskFinished: true);
 
			return taskInfo.ResultUrls;
		}
 
		private static async Task<Guid> UploadFilesAsync(IOcrClient ocrClient)
		{
			ImageSubmittingParams submitParams;
			string firstFilePath = "Image_letter_1.tif";
			string secondFilePath = "Image_article_de.jpg";
 
			// First file
			using (var fileStream = new FileStream(firstFilePath, FileMode.Open))
			{
				var submitImageResult = await ocrClient.SubmitImageAsync(
					null,
					fileStream,
					Path.GetFileName(firstFilePath));
 
				// Save TaskId for next files and ProcessDocument method
				submitParams = new ImageSubmittingParams { TaskId = submitImageResult.TaskId };
			}
 
			// Second file
			using (var fileStream = new FileStream(secondFilePath, FileMode.Open))
			{
				await ocrClient.SubmitImageAsync(
					submitParams,
					fileStream,
					Path.GetFileName(secondFilePath));
			}
 
			return submitParams.TaskId.Value;
		}
	}
}

Exercise #1: Implement the Text Extraction scenario

  1. Specify the method to process an image
  2. Set the processing profile to textExtraction
  3. Set the export format to txt and xml
  4. Set the recognitions languages to English and Spanish
  5. (Optional) Specify the parameter to write formatting information
  6. (Optional) Specify the parameter to write the recognition variants
  7. Image(s) to process: Image_article.jpg, image_invoice_es.tif
  8. Process the image(s) and review the result

Result Excercise #1

Result Excercise #1

// Copyright © 2019 ABBYY Production LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
 
using Abbyy.CloudSdk.V2.Client.Models;
using Abbyy.CloudSdk.V2.Client.Models.Enums;
using Abbyy.CloudSdk.V2.Client.Models.RequestParams;
using System;
using System.Collections.Generic;
using System.IO;
using System.Threading.Tasks;
 
namespace Abbyy.CloudSdk.V2.Client.Sample
{
	public class Program
	{
		private const string ApplicationId = "Enter APP ID";
		private const string Password = "Enter PWD";
		private const string FilePath = "Image_article.jpg";
 
		/// <summary>
		/// Processing Location URL https://www.ocrsdk.com/documentation/specifications/data-processing-location/
		/// </summary>
		private const string ServiceUrl = "https://cloud-westus.ocrsdk.com";
 
		private static AuthInfo _authInfo;
 
		public static async Task Main()
		{
			_authInfo = new AuthInfo
			{
				Host = ServiceUrl,
				ApplicationId = ApplicationId,
				Password = Password,
			};
 
			var resultUrls = await ProcessImageAsync();
 
 
			foreach (var resultUrl in resultUrls)
			{
				Console.WriteLine(resultUrl);
			}
		}
 
		private static async Task<List<string>> ProcessImageAsync()
		{
			var imageParams = new ImageProcessingParams
			{
				Profile = ProcessingProfile.TextExtraction,
				Language = "English, Spanish",
				ExportFormats = new[] { ExportFormat.Txt, ExportFormat.Xml },
				//WriteFormatting = true,
				//WriteRecognitionVariants = true,
			};
 
			using (var client = new OcrClient(_authInfo))
			using (var fileStream = new FileStream(FilePath, FileMode.Open))
			{
				var taskInfo = await client.ProcessImageAsync(
					imageParams,
					fileStream,
					Path.GetFileName(FilePath),
					waitTaskFinished: true);
 
				return taskInfo.ResultUrls;
			}
		}
	}
}

Exercise #2: Extract data from an ID document (MRZ)

  1. Specify a method to process Machine Readable Zone (MRZ)
  2. Image to process: Image_MRZ.jpg
  3. Process an ID document and review the result

Result Exercise#2 - ProcessMrz

Result Exercise#2 - ProcessMrz

// Copyright © 2019 ABBYY Production LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
 
using Abbyy.CloudSdk.V2.Client.Models;
using Abbyy.CloudSdk.V2.Client.Models.Enums;
using Abbyy.CloudSdk.V2.Client.Models.RequestParams;
using System;
using System.Collections.Generic;
using System.IO;
using System.Threading.Tasks;
 
namespace Abbyy.CloudSdk.V2.Client.Sample
{
	public class Program
	{
		private const string ApplicationId = "Enter APP ID";
		private const string Password = "Enter PWD";
		private const string FilePath = "Image_MRZ.jpg";
 
		/// <summary>
		/// Processing Location URL https://www.ocrsdk.com/documentation/specifications/data-processing-location/
		/// </summary>
		private const string ServiceUrl = "https://cloud-westus.ocrsdk.com";
 
		private static AuthInfo _authInfo;
 
		public static async Task Main()
		{
			_authInfo = new AuthInfo
			{
				Host = ServiceUrl,
				ApplicationId = ApplicationId,
				Password = Password,
			};
 
			var resultUrls = await ProcessMrzAsync();
 
			foreach (var resultUrl in resultUrls)
			{
				Console.WriteLine(resultUrl);
			}
		}
 
		private static async Task<List<string>> ProcessMrzAsync()
		{
			var imageParams = new MrzProcessingParams();
 
			using (var client = new OcrClient(_authInfo))
			using (var fileStream = new FileStream(FilePath, FileMode.Open))
			{
				var taskInfo = await client.ProcessMrzAsync(
					imageParams,
					fileStream,
					Path.GetFileName(FilePath),
					waitTaskFinished: true);
 
				return taskInfo.ResultUrls;
			}
		}
	}
}

Exercise #3: Extract data from a business card

  1. Specify a method to process a business card
  2. Change export format to xml (default is vCard)
  3. Set the parameter to write the field components
  4. Image to process: Image_BCR.jpg
  5. Process a business card and review the result

Result: Exercise #3 - ProcessBusinessCard

Result: Exercise #3 - ProcessBusinessCard

 
// Copyright © 2019 ABBYY Production LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
 
using Abbyy.CloudSdk.V2.Client.Models;
using Abbyy.CloudSdk.V2.Client.Models.Enums;
using Abbyy.CloudSdk.V2.Client.Models.RequestParams;
using System;
using System.Collections.Generic;
using System.IO;
using System.Threading.Tasks;
 
namespace Abbyy.CloudSdk.V2.Client.Sample
{
	public class Program
	{
		private const string ApplicationId = "Enter APP ID";
		private const string Password = "Enter PWD";
		private const string FilePath = "Image_BCR.jpg";
 
		/// <summary>
		/// Processing Location URL https://www.ocrsdk.com/documentation/specifications/data-processing-location/
		/// </summary>
		private const string ServiceUrl = "https://cloud-westus.ocrsdk.com";
 
		private static AuthInfo _authInfo;
 
		public static async Task Main()
		{
			_authInfo = new AuthInfo
			{
				Host = ServiceUrl,
				ApplicationId = ApplicationId,
				Password = Password,
			};
 
			var resultUrls = await ProcessBusinessCardAsync();
 
 
			foreach (var resultUrl in resultUrls)
			{
				Console.WriteLine(resultUrl);
			}
		}
 
		private static async Task<List<string>> ProcessBusinessCardAsync()
		{
			var imageParams = new BusinessCardProcessingParams
			{
				ExportFormats = BusinessCardExportFormat.Xml,
				WriteFieldComponents = true,				
			};
 
			using (var client = new OcrClient(_authInfo))
			using (var fileStream = new FileStream(FilePath, FileMode.Open))
			{
				var taskInfo = await client.ProcessBusinessCardAsync(
					imageParams,
					fileStream,
					Path.GetFileName(FilePath),
					waitTaskFinished: true);
 
				return taskInfo.ResultUrls;
			}
		}
	}
}

Handout for the hands-on session

This website uses cookies which enable you to see pages or use other functions of our websites. You can turn off such cookies in your browser’s settings. If you continue to use these pages, you consent to the use of cookies.
  • No tags, yet