Finding paragraph bounding boxes

Contents
[ ]

Aspose.OCR for Python via .NET can automatically find the coordinates of image regions containing text paragraphs. This can be useful for highlighting detected areas when previewing an image.

To get bounding boxes of all paragraphs in images, provided in OcrInput object, use detect_rectangles() method. Specify AreasType.PARAGRAPHS as the areas_type parameter of the method. detect_areas parameter of the method is ignored.

The method returns a list of RectangleOutput objects containing coordinates of each paragraph in each image.

Property Description
rectangles Coordinates of each paragraph of an image (top-left corner, width and height), returned as a list of Rectangle objects.
image_index Sequence number of the image on the page. When working with single-page images, this value is always 0.
page Page number. When working with single-page images, this value is always 0.
source The full path or URL of the source file. If the file is provided as a stream, an array of pixels, or a Base64 string, this value will be empty.

Example

The following code example shows how to detect paragraphs in multiple images:

# Instantiate Aspose.OCR API
api = AsposeOcr()
# Add image to the recognition batch
input = OcrInput(InputType.SINGLE_IMAGE)
input.add("source.png")
# Detect paragraphs
results = api.detect_rectangles(input, AreasType.PARAGRAPHS)
for region in results[0].rectangles:
    print(region.top + ", " + region.left + ", " + region.width + ", " + region.height)