Tesseract OCR Text Position

前端 未结 1 1217
耶瑟儿~
耶瑟儿~ 2021-02-02 03:31

I am working on OCR using tesseract. I am able to make the application working and get the output. Here i\'m trying to extract data from an invoice bill and getting the extracte

相关标签:
1条回答
  • 2021-02-02 04:09

    You can loop through found items in the page using page.GetIterator(). For the individual items you can get a 'bounding box', this is a Tesseract.Rect (rectangle struct) which contains: X1, Y1, X2, Y2 coordinates.

    Tesseract.PageIteratorLevel myLevel = /*TODO*/;
    using (var page = Engine.Process(img))
    using (var iter = page.GetIterator())
    {
        iter.Begin();
        do
        {
            if (iter.TryGetBoundingBox(myLevel, out var rect))
            {
                var curText = iter.GetText(myLevel);
                // Your code here, 'rect' should containt the location of the text, 'curText' contains the actual text itself
            }
        } while (iter.Next(myLevel));
    }
    

    There is no clear-cut way to use the positions in the input to space the text in the output. You're going to have to write some custom logic for that.

    You might be able to estimate the number of spaces you need to the left of your text with something like this:

    var padLeftSpaces = (int)Math.Round((rect.X1 / inputWidth) * outputWidthSpaces);
    
    0 讨论(0)
提交回复
热议问题