Hello, world!
Contents
[
Hide
]
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.
We assume that you already have a basic knowledge of Microsoft Visual Studio and C#.
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
- Create a new C# project in Visual Studio. You can use a very basic project template, such as Console App.
- Install Aspose.OCR (CPU-based) NuGet package to the project.
- Save this image to bin\Debug or bin\Debug\net6.0 directory of the project under the name
source.png
:
Coding
- Create an instance of Aspose.OCR recognition engine:
Aspose.OCR.AsposeOcr recognitionEngine = new Aspose.OCR.AsposeOcr();
- Add the image to
OcrInput
object:Aspose.OCR.OcrInput source = new Aspose.OCR.OcrInput(Aspose.OCR.InputType.SingleImage); source.Add("source.png");
- Extract text from the image:
List<Aspose.OCR.RecognitionResult> results = recognitionEngine.Recognize(source);
- 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");
List<Aspose.OCR.RecognitionResult> 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.
If you use your own image, consider the trial restrictions.
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.