Location of identified text

Hello Aspose,

I would like to perform a text search within a jpeg image and receive all occurances found in x,y coordinate relative to the top most left poinht of the image file.

How can I do that?

Regards,

T.

Hi Tzach,

Thank you for considering Aspose products.

You may use OcrEngine.Text.PartsInfo property for your requirement. The said property enables you to retrieve an array of recognized text by parts. Each individual part of recognized text carries the information such as font, style, size and the location of the symbol in x,y coordinates. Below provided code snippet exhibits the usage,

C#


// image document on which OCR is to be performed
string imageFile = (MyDir + “sample.jpg”);

// Initialize OcrEngine
OcrEngine ocr = new OcrEngine();

// Configure to use Default Dictionaries
ocr.Config.UseDefaultDictionaries = true;

// Load Image
ocr.Image = ImageStream.FromFile(imageFile);

// Add language
ocr.Languages.AddLanguage(Language.Load(“english”));

// Load the resource file
using (ocr.Resource = new FileStream(resourceFileName, FileMode.Open))
{
try
{
// Process the whole image
if (ocr.Process())
{
// Retrieve an array of recognized text by parts
IRecognizedTextPartInfo [] text = ocr.Text.PartsInfo;
// Iterate over the text parts
foreach (IRecognizedTextPartInfo symbol in text)
{
// Print part location
Console.WriteLine(“Symbol:”+ symbol.Text + " Location:" + symbol.Box.Location);
}

}
}
catch (Exception ex)
{
Console.WriteLine("Exception: " + ex.Message);
}
}