HTML
JPG
OCR
XML
BMP
OCR
Get areas with text coordinates in C#
Automatically find the coordinates of image regions containing text paragraphs using Aspose.OCR for .NET library.
How to get text areas coordinates using C#
To get bounding boxes of all paragraphs in images, provided in OcrInput object, use Aspose.OCR.AsposeOcr.DetectRectangles method. Specify Aspose.OCR.AreasType.PARAGRAPHS as the areasType parameter of the method. detectAreas parameter of the method is ignored.
To run the examples, you just need to download the Aspose.OCR tools with the following links:
Command line tools
GetAreasWithTextCoordinates project
Run program in Command Prompt
GetAreasWithTextCoordinates
or
Run program in Command Prompt if you want to use own image (document)
GetAreasWithTextCoordinates folder/image.png
Recognition result
Property | Type | Description |
---|---|---|
Rectangles | List | Coordinates of each paragraph of an image (top-left corner, width and height), returned as a list of Rectangle objects. |
ImageIndex | int | Sequence number of the image on the page. When working with single-page images, this value is always 0. |
Page | int | Page number. When working with single-page images, this value is always 0. |
Source | string | The full path of the source file. If the file is provided as a MemoryStream object, an array of pixels, or a Base64 string, this value will be empty. |
This sample code shows how to get areas coordinates
// Set the license file
//License lic = new License();
//lic.SetLicense("Aspose.Total.lic");
// Create AsposeOcr instance.
// You can use the overloaded constructor to set characters restriction.
AsposeOcr api = new AsposeOcr();
// Create OcrInput object to containerize images
OcrInput input = new OcrInput(InputType.SingleImage);
input.Add(fileName);
// set
// 1) the full path to the image
// 2) type of areas to search
// 3) set this to true for AreasType.LINES if you want to split lines after defining paragraphs
List<RectangleOutput> result = api.DetectRectangles(input, AreasType.PARAGRAPHS, detectAreas: true);
Console.WriteLine("AREAS RECTANGLES COORDINATES:");
Console.WriteLine("RESULT");
Console.ResetColor();
Console.WriteLine("------------------------------------------------------------------------------");
// Print the result
for (int i = 0; i < result.Count; i++)
{
Console.WriteLine(result[i].Source);
foreach(Rectangle rect in result[i].Rectangles)
Console.WriteLine($"X: {rect.X} Y: {rect.Y} Width: {rect.Width} Height: {rect.Height}");
}
Other Supported Tools
Using C#, one can easily run our examples.
Recognize image (GIF, PNG, JPEG, BMP, TIFF, JFIF)
Recognize PDF (Scanned PDF)
Recognize TIFF (Multipage TIFF)
Preprocess image (GIF, PNG, JPEG, BMP, TIFF, JFIF)
Recognize ZIP archive (ZIP)
Get JSON (GIF, PNG, JPEG, BMP, TIFF, JFIF)
Get XLSX (GIF, PNG, JPEG, BMP, TIFF, JFIF)
Detect angle (GIF, PNG, JPEG, BMP, TIFF, JFIF)
Recognize image from URL (URL with GIF, PNG, JPEG, BMP, TIFF, JFIF)
Text areas detection (GIF, PNG, JPEG, BMP, TIFF, JFIF)