DEV Community

IronSoftware
IronSoftware

Posted on • Originally published at ironsoftware.com

OCR a Region of an Image (Code Example)

This examples renders a 41% speed improvement by choosing a specific area of an image to perform OCR in .NET.
These are called ContentAreas or CropAreas.

C#:

using IronOcr;

var Ocr = new IronTesseract();

using (var Input = new OcrInput())
    {
    // a 41% improvement on speed by specifiying a pixel region
    var ContentArea = new System.Drawing.Rectangle() { X = 215, Y = 1250, Height = 280, Width = 1335 };
    Input.AddImage("img/example.png", ContentArea);

    var Result = Ocr.Read(Input);
    Console.WriteLine(Result.Text);
}
Enter fullscreen mode Exit fullscreen mode

VB:

Imports IronOcr

Private Ocr = New IronTesseract()

Using Input = New OcrInput()
    ' a 41% improvement on speed by specifiying a pixel region
    Dim ContentArea = New System.Drawing.Rectangle() With {
        .X = 215,
        .Y = 1250,
        .Height = 280,
        .Width = 1335
    }
    Input.AddImage("img/example.png", ContentArea)

    Dim Result = Ocr.Read(Input)
    Console.WriteLine(Result.Text)
End Using
Enter fullscreen mode Exit fullscreen mode

Top comments (0)