Different results in IronOcr reading full image or partial contentArea

Viewed 22

I'm using IronOcr/Tesseract to extract text from an image. I want to know the location of a pre-known piece of text and using this found rectangle to extract text from other images.

To verify the method, i used the same image twice, so i should get back the same piece of text i was looking for earlier.

However, when i use this rectangle to narrow down the 2nd search, i get no results. Since no configuration, scaling, or resolution is changed between these two operations, i'm wondering why this is. What am i doing wrong here?

        var _recognizerIron = new IronTesseract();           
        const string file = "assets/sample.jpg";
        using var input = new OcrInput(file);
        var result = _recognizerIron.Read(input);
        
        var foundWord = result.Words.First(w => w.Text=="7210");
        // foundWord.Location: {X = 511 Y = 793 Width = 67 Height = 22}

        using var input2 = new OcrInput();
        input2.AddImage(file, new CropRectangle(foundWord.Location));
        var result2 = _recognizerIron.Read(input2);
        
        Console.Write(result2.Text);
        //Expected Result: result2.Text=="7210"
        //Actual Result: result2.Text==""
1 Answers

IronOCR may automatically upscale images to improve read accuracy.

To disable this behavior, set TargetDPI = null on OcrInput

using IronOcr;
var Ocr = new IronTesseract();
using (var Input = new OcrInput())
{
    Input.TargetDPI = null; //disable upscaling
    Input.AddImage("example.png");
    var Result = Ocr.Read(Input);
    Console.WriteLine(Result.Text);
}

Trouble-shooting articles on IronOcr:

X and Y coordinates change in OcrResult Class

Examples of how to use TargetDPI

Related