Search Results for

    Show / Hide Table of Contents

    Class OcrResult.OcrResultElement

    Lowest level of abstract OcrResult DOM element. All result objects extend from this including OcrResult.Barcode, OcrResult.Character, OcrResult.Word, OcrResult.Line, OcrResult.Paragraph ...

    Inheritance
    System.Object
    OcrResult.OcrResultElement
    OcrResult.Barcode
    OcrResult.OcrResultTextElement
    Namespace: IronOcr
    Assembly: IronOcr.dll
    Syntax
    public abstract class OcrResultElement : Object

    OcrResult.OcrResultElement is the shared base every positioned item in an OCR result inherits, so any time you ask where a recognized piece of text or a detected barcode sits on the page, you are reading members declared here. It supplies the geometry common to the whole result tree, which is what lets you draw boxes, crop regions, or map coordinates back to the source image regardless of whether the item is a character, a word, a line, or a barcode.

    Every element exposes its position and size through X, Y, Width, and Height, all measured in pixels from the top-left of the source page. Location bundles the same geometry into a single Rectangle when you would rather pass one value than four. The element does not hold the text itself; the richer text subclasses add Text, Confidence, and the navigation members on top of this geometry. Because the type is abstract, you never construct one directly. You receive concrete subclasses by walking an OcrResult returned from IronTesseract.Read, then reading these inherited members on each item.

    ToBitmap takes the originating OcrInput and returns an AnyBitmap cropped to that element, which is handy for saving a snippet of a detected region or feeding it to a downstream step. Two branches extend this base directly: OcrResult.Barcode for detected barcodes, and OcrResult.OcrResultTextElement, the parent of the text-bearing elements such as OcrResult.Character, OcrResult.Line, and OcrResult.Block.

    using IronOcr;
    
    var ocr = new IronTesseract();
    using var input = new OcrInput("scan.png");
    OcrResult result = ocr.Read(input);
    foreach (OcrResult.Word word in result.Words)
        Console.WriteLine($"{word.Text} at {word.X},{word.Y} ({word.Width}x{word.Height})");

    The working with OCR results how-to walks through the result tree, the highlight text as images how-to uses element geometry to crop regions, and the results objects example shows reading geometry from each element.

    Constructors

    OcrResultElement()

    Declaration
    protected OcrResultElement()

    Properties

    Height

    Height in Pixels

    Declaration
    public int Height { get; }
    Property Value
    Type Description
    System.Int32

    Location

    Returns a IronSoftware.Drawing.Rectangle of the location and size of this element within an OCR page. Units are pixels and reference locations on the source image.

    Declaration
    public Rectangle Location { get; }
    Property Value
    Type Description
    IronSoftware.Drawing.Rectangle

    Width

    Width in Pixels

    Declaration
    public int Width { get; }
    Property Value
    Type Description
    System.Int32

    X

    Position of this OCR Results object on the source image (page) in pixels counted from the left edge.

    Declaration
    public int X { get; }
    Property Value
    Type Description
    System.Int32

    Y

    Position of this OCR Results object on the source image (page) in pixels counted down from the top edge.

    Declaration
    public int Y { get; }
    Property Value
    Type Description
    System.Int32

    Methods

    ToBitmap(OcrInput)

    Returns an image of this element.

    Declaration
    public AnyBitmap ToBitmap(OcrInput Input)
    Parameters
    Type Name Description
    OcrInput Input

    The OcrInput document that was read by IronTesseract

    Returns
    Type Description
    IronSoftware.Drawing.AnyBitmap

    A IronSoftware.Drawing.AnyBitmap.

    ☀
    ☾
    Downloads
    • Download with Nuget
    • Start for Free
    In This Article
    Back to top
    Install with Nuget