Recognition

Reading text from any content in Aspose.OCR for .NET is as easy as calling a universal Aspose.OCR.AsposeOcr.Recognize method.

This method takes OcrInput object and optional recognition settings.

Recognition results are returned as a list of Aspose.OCR.RecognitionResult objects, that allow you to perform advanced manipulations with recognition results: automatically correct spelling, get image regions and save results in various formats.

Aspose.OCR.AsposeOcr recognitionEngine = new Aspose.OCR.AsposeOcr();
// Add images to OcrInput object
Aspose.OCR.OcrInput input = new Aspose.OCR.OcrInput(Aspose.OCR.InputType.SingleImage);
input.Add("source1.png");
input.Add("source2.jpg");
// Set recognition language
Aspose.OCR.RecognitionSettings recognitionSettings = new Aspose.OCR.RecognitionSettings();
recognitionSettings.Language = Aspose.OCR.Language.Ukr;
// Recognize image
List<Aspose.OCR.RecognitionResult> results = recognitionEngine.Recognize(input, recognitionSettings);
foreach(Aspose.OCR.RecognitionResult result in results)
{
	Console.WriteLine(result.RecognitionText);
}

Cancelling recognition

Aspose.OCR for .NET allows you to forcibly cancel the recognition process either manually or automatically after the specified number of milliseconds. The cancellation process is based on the standardized System.Threading.CancellationTokenSource object and flows.

The recognition is immediately cancelled regardless of the number of threads.

// Set automatic cancellation after 20 seconds (20,000ms)
CancellationTokenSource cancellationTokenSource  = new CancellationTokenSource();
cancellationTokenSource.CancelAfter(20000);
// Initialize Aspose.OCR for .NET recognition API
Aspose.OCR.AsposeOcr recognitionEngine = new Aspose.OCR.AsposeOcr();
// Add scanned PDF to recognition batch
Aspose.OCR.OcrInput input = new Aspose.OCR.OcrInput(Aspose.OCR.InputType.PDF);
input.Add("large.pdf");
// Recognize image
List<Aspose.OCR.RecognitionResult> results = recognitionEngine.Recognize(input, null, cancellationTokenSource.Token);