Extracting text inside a rectangle

Contents
[ ]

Aspose.OCR allows you to extract names, dates, numbers, and other blocks from certain areas of uniform images, such as ID cards, visas, driver’s licenses, applications, and so on. Regions can be provided manually or automatically detected using the Aspose.OCR.AsposeOcr.DetectRectangles method.

To extract text from one or more areas of an image, provide a list of Aspose.Drawing.Rectangle objects specifying the upper left corner and the width and height of the image area in RecognitionAreas field of RecognitionSettings.

Aspose.OCR.AsposeOcr recognitionEngine = new Aspose.OCR.AsposeOcr();
// Manually specify recognition areas
List<Aspose.Drawing.Rectangle> rectangles = new List<Aspose.Drawing.Rectangle>(){
	new Aspose.Drawing.Rectangle(231,101,430,42),
	new Aspose.Drawing.Rectangle(546,224,123,26)
};
Aspose.OCR.RecognitionSettings recognitionSettings = new Aspose.OCR.RecognitionSettings();
recognitionSettings.RecognitionAreas = rectangles;
// Recognize image
Aspose.OCR.OcrInput input = new Aspose.OCR.OcrInput(Aspose.OCR.InputType.SingleImage);
input.Add("source.png");
List<Aspose.OCR.RecognitionResult> results = recognitionEngine.Recognize(input, recognitionSettings);
// Output recognition results for each area
Console.WriteLine("Name: "+results[0].RecognitionAreasText[0]);
Console.WriteLine("Expiry: "+results[0].RecognitionAreasText[1]);

The text from each rectangle is returned in the RecognitionAreasText property of the recognition result.

Live demo

Driver's license

Block Coordinates Extracted text
Name {X=231, Y=101, Width=430, Height=42} SAMPLE
AVERY JOSEPH
Expiry date {X=546, Y=224, Width=123, Height=26} 08/15/2022