Convert Image to Text with OCR in C#

convert Image to Text in C#

Transform your scanned image to a string programmatically using this .NET OCR library. This library lets you perform OCR (Optical Character Recognition) in which alphabets on the images are extracted and then organized to be saved to any file format. This blog post will explore this library and write the code snippet to convert image to text with OCR in C#. However, this library offers a wide range of methods to scan and convert images into text format programmatically.

We will cover the following points:

.NET OCR Library Installation

We are going to use this library that is cost-effective and robust for OCR. It is easy to install and offers pre-processing filters that help to recognize rotated images. However, you can either download the DLL files or run the following command in the NuGet package manager to install this API in your .NET project.

Install-Package Aspose.OCR

Convert Image to Text with OCR in C#

You can extract text from a scanned image and save it into any other file format by writing a few lines of source code.

Follow the following steps and the code snippet to convert an image to text with OCR in C# programmatically:

  1. Initialize an instance of AsposeOcr.
  2. Load the source image file by invoking the RecognizeImage method that recognizes text on the image.
  3. Display the text.

The following code snippet shows how to convert image to text with OCR in C#:

OCR Operation on the Image Containing a Single Line of Text in C#

This library lets you perform OCR operations on images that contain only a single line. You may follow the following steps mentioned below:

  1. Create an object of AsposeOcr class.
  2. Call RecognizeLine method that recognizes image that contains a single line of text.
  3. Display the recognized text.

The code sample below demonstrates how to convert image to text with OCR in C# where the image contains only a single line of text:

Performing OCR on an Image From a Stream in C#

You may also perform Optical Character Recognition on the images in a stream. The same method will be called as used in the first section above.

The following are the steps:

  1. Instantiate an instance of AsposeOcr class.
  2. Initialize the constructors of MemoryStream class to create a stream.
  3. Load the source image file by initializing the FileStream constructor.
  4. Call the CopyTo method to write the bytes of the current stream to the memory stream.
  5. Invoke the RecognizeImage method to read the text from the image.

The sample code below elaborates on how to convert an image from a stream to text by performing OCR in C#:

Get a Free License

You may get a free temporary license to try the API without evaluation limitations.

Summing up

This brings us to the end of this blog post. We have gone through how to convert image to text with OCR in C# programmatically. In addition, we also have gone through some advanced methods this .NET OCR library provides. Moreover, you may visit the documentation to know the other features. Further, you may find the code examples along with method descriptions here. We will publish other interesting articles soon. Therefore, stay in touch with conholdate.com for regular updates.

Ask a question

You can let us know about your questions or queries on our forum.

FAQs

What is OCR C#?

Optical Character Recognition is a technique to read text from scanned images programmatically. You may visit this link to know further details.

How do I read text from an image?

You can use this RecognizeImage method of this .NET OCR library to convert image to text using OCR.

See Also