Hello, world!

In this article, you will learn how to build a bare minimum console application for extracting text from an image with with Aspose.OCR for .NET.

You will need

  • A compatible system with Microsoft Visual Studio installed. As an individual developer, you can use a free Visual Studio Community Edition.
  • Some image containing a text. You can simply download the one from the article.
  • 5 minutes of spare time.

Preparing

  1. Create a new C# project in Visual Studio. You can use a very basic project template, such as Console App.
  2. Install Aspose.OCR (CPU-based) NuGet package to the project.
  3. Save this image to bin\Debug or bin\Debug\net6.0 directory of the project under the name source.png:
    Source image

Coding

  1. Create an instance of Aspose.OCR recognition engine:
    Aspose.OCR.AsposeOcr recognitionEngine = new Aspose.OCR.AsposeOcr();
    
  2. Add the image to OcrInput object:
    Aspose.OCR.OcrInput source = new Aspose.OCR.OcrInput(Aspose.OCR.InputType.SingleImage);
    source.Add("source.png");
    
  3. Extract text from the image:
    Aspose.OCR.OcrOutput results = recognitionEngine.Recognize(source);
    
  4. Output the recognized text:
    Console.WriteLine(results[0].RecognitionText);
    

Full code:

Aspose.OCR.AsposeOcr recognitionEngine = new Aspose.OCR.AsposeOcr();
Aspose.OCR.OcrInput source = new Aspose.OCR.OcrInput(Aspose.OCR.InputType.SingleImage);
source.Add("source.png");
Aspose.OCR.OcrOutput results = recognitionEngine.Recognize(source);
Console.WriteLine(results[0].RecognitionText);

Running

Run the program. You will see extracted text in the console output:

Hello, World! I can read this text.

What’s next

Congratulations! You have extracted the text from the image. Read the Developer reference and API reference for details on developing advanced applications with Aspose.OCR for .NET.