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 GetRectangles method of Aspose.OCR.AsposeOcr class.

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();
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.AutoDenoising = true;
recognitionSettings.RecognitionAreas = rectangles;
Aspose.OCR.RecognitionResult result = recognitionEngine.RecognizeImage("dl.png", recognitionSettings);
Console.WriteLine("Name: "+result.RecognitionAreasText[0]);
Console.WriteLine("Expiry: "+result.RecognitionAreasText[1]);

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

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