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 found automatically using the paragraph, line or word detection.

To extract text from one or more areas of an image, provide region boundaries (the upper left corner and the width and height) to one of the following methods:

Method Description
page_rect() Extract text from specified image areas.
page_rect_from_raw_bytes() Extract text from specified areas of an image provided as an array of pixels.
asposeocr_page_rect_abc() Read only the predefined list of characters from specified image areas.
asposeocr_page_rect_abc_from_raw_bytes() Read only the predefined list of characters from specified areas of an image provided as an array of pixels.
std::string image_path = "source.png";
const size_t len = 4096;
wchar_t buffer[len] = { 0 };
int x = 138, y = 352, w = 2033, h = 537;
size_t size = aspose::ocr::page_rect(image_path.c_str(), buffer, len, x, y, w, h);
std::wcout << buffer << L"\n";

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