OCR Image to Text and Spelling Correction in C#

We can perform OCR on images or scanned documents and extract textual data programmatically using C#. We can then run a spell checker to correct spelling errors in the recognized text. In this article, we will learn how to perform OCR image to text and spelling correction in C#.

The following topics shall be covered in this article:

  1. OCR Image to Text and Spelling Correction C# API
  2. OCR Image to Text and Get Spelling Mistakes
  3. Convert Image to Text with Spelling Correction
  4. Save Recognized Text with Corrected Spelling
  5. Spell Check Custom Text

OCR Image to Text and Spelling Correction C# API

We will be using the Aspose.OCR for .NET API to perform OCR on images, text extraction and spelling correction. It can recognize scanned images, smartphone photos, screenshots, areas of images, and scanned PDFs. It returns recognized text results in the most popular document and data exchange formats. The API also allows converting images to text and creating searchable PDFs from scans. Moreover, it allows autocorrecting spelling mistakes in the recognized text.

The AsposeOcr class is the main API for the Aspose OCR library. It provides various methods to perform OCR operations. The RecognizeImage() method of this class recognizes text on the images of the supported formats. The CorrectSpelling() method of the API replaces misspelled words with correct words in the text. The RecognitionResult class represents the results of the image recognition. The Save(string, SaveFormat, bool, SpellCheckLanguage, string) method of this class saves the document as plain text, PDF or Microsoft Word Document. All the supported languages for spell check are defined in SpellCheckLanguage enumeration.

Please either download the DLL of the API or install it using NuGet.

PM> Install-Package Aspose.OCR

OCR Image to Text and Get Spelling Mistakes in C#

We can perform OCR on images and get a list of spelling errors in the recognized text by following the steps given below:

  1. Firstly, create an instance of the AsposeOcr class.
  2. Next, initialize an object of the RecognitionSettings class.
  3. Then, get RecognitionResult by calling the RecognizeImage() method. It takes the image path and RecognitionSettings object as arguments.
  4. After that, call the GetSpellCheckErrorList() method to get a list of misspelled words with suggestions.
  5. Finally, loop through the SpellCheckError list and show results.

The following sample code shows how to get a list of spelling mistakes from a recognized text in C#.

OCR Image to Text and Get Spelling Mistakes in C#

Get a list of spelling mistakes in C#

Convert Image to Text with Spelling Correction in C#

We can convert an image to text and autocorrect spelling errors by following the steps given below:

  1. Firstly, create an instance of the AsposeOcr class.
  2. Next, initialize an object of the RecognitionSettings class.
  3. Then, get RecognitionResult by calling the RecognizeImage() method. It takes the image path and RecognitionSettings object as arguments.
  4. After that, call the GetSpellCheckCorrectedText() method to get text with spelling correction.
  5. Finally, show the results.

The following sample code shows how to autocorrect spelling errors from a recognized text in C#.

Convert Image to Text with Spelling Correction in C#

Convert Image to Text with Spelling Correction in C#

Save Recognized Text with Corrected Spelling in C#

We can save the recognized text from an image after spelling correction by following the steps given below:

  1. Firstly, create an instance of the AsposeOcr class.
  2. Next, initialize an object of the RecognitionSettings class.
  3. After that, get RecognitionResult by calling the RecognizeImage() method. It takes the image path and RecognitionSettings object as arguments.
  4. Finally, call the Save(string, SaveFormat, bool, SpellCheckLanguage) method to save the text. It takes the applySpellingCorrection bool value as true.

The following sample code shows how to save the text with spelling correction in C#.

Spell Check Text in C#

We can also run spell check on a custom text by following the steps given below:

  1. Firstly, create an instance of the AsposeOcr class.
  2. Next, call the CorrectSpelling() method. It takes the text to correct and SpellCheckLanguage as arguments.
  3. Finally, show the results.

The following sample code shows how to spell-check custom text in C#.

This is sample text with errors

Get a Free Evaluation License

You can get a free temporary license to try Aspose.OCR for .NET without evaluation limitations.

Conclusion

In this article, we have learned how to:

  • perform OCR and recognize text on image in C#;
  • get a list of the misspelled words along with correct word suggestions;
  • autocorrect spelling mistakes;
  • save the corrected text programmatically.

Besides, you can learn more about Aspose.OCR for .NET API using the documentation. In case of any ambiguity, please feel free to contact us on our forum.

See Also