Finding word bounding boxes
Contents
[
Hide
]
Aspose.OCR allows you to automatically find the coordinates of image rectangles containing text words. This can be useful for highlighting detected areas when previewing an image or extracting individual blocks of text.
To get bounding boxes of all words of the image, use one of the following methods:
Method | Description |
---|---|
get_rectangles_number() |
Get the total number of words in the image. |
get_rectangles_number_from_raw_bytes() |
Get the total number of words in the image provided as an array of pixels. |
get_rectangles_number_from_uri() |
Get the total number of words in the image provided by URI. This method is not supported in the Linux version of Aspose.OCR for C++. |
get_rectangles() |
Get coordinates of all word in the image. Make sure to use the same parameters as in get_rectangles_number() method. |
get_rectangles_from_raw_bytes() |
Get coordinates of all word in the image provided as an array of pixels. Make sure to use the same parameters as in get_rectangles_number_from_raw_bytes() method. |
get_rectangles_from_uri() |
Get coordinates of all word in the image provided by URI. Make sure to use the same parameters as in get_rectangles_number_from_uri() method.This method is not supported in the Linux version of Aspose.OCR for C++. |
Set type
parameter of the method to areas_type::words
.
std::string image_path = "source.png";
// calculate the number of words
size_t res_len = aspose::ocr::get_rectangles_number(image_path.c_str(), areas_type::words, false);
std::wcout << "Number of words: " << res_len << std::endl;
// get word bounding boxes
rect* rectangles = new rect[res_len];
res_len = aspose::ocr::get_rectangles(image_path.c_str(), areas_type::words, false, rectangles, res_len);
std::wcout << "words: " << std::endl;
for (size_t i = 0; i < res_len; i++)
{
std::wcout << " x: " << rectangles[i].x << " y: " << rectangles[i].y << " width: " << rectangles[i].width << " height: " << rectangles[i].height << std::endl;
}
Coordinates of each word (top-left corner, width and height) are returned as an array of rect
objects.