Best practise

We recommend creating a static class with different OcrEngineParameters which work best for your application.

Use these settings in the ConfigureElementProperties method like any other Setting:

public partial class HomeScreen
{
    partial void ConfigureElementProperties()
    {
        DemoTextbox.TextBoxOcrParas.SearchPattern = OcrParams.SearchPatternTime;
        DemoButton.TextParameters = OcrParams.ColorfulText;
    }
}

Find some examples for OcrEngineParameters below:

public static class OcrParams
{
    //use as OCREngineParameters.SearchPattern
    public const string SearchPatternDateTime = @"^0^0/^0^0/^0^0^0^0 ^0^0:^0^0";
    public const string SearchPatternTime = @"^0^0:^0^0";


    //use incase of very colorful text or background, like red background and white text
    public static OcrEngineParameters ColorfulText => new OcrEngineParameters
    {
        OcrEngine = OcrEngines.LEADEngine,
        SearchLevel = SearchLevel.Words,
        Preprocessing = new OcrPreprocessingParameters
        {
            Upscale = true,
            UseBinarizeModification = true,
            BinarizeThreshold = 180, // 180 ensures that blue, yellow and red all go to black (and then inverted to white)
            UseInvertModification = true,
            UseSharpnessModification = true,
            SharpnessValue = 50
        }
    };

    //try for texts where the default settings do not work
    public static OcrEngineParameters TextAlternative => new OcrEngineParameters
    {
        OcrEngine = OcrEngines.LEADEngine,
        SearchLevel = SearchLevel.StringComparison,
        Accuracy = 0.4,
        Preprocessing = new OcrPreprocessingParameters { Upscale = true }
    };

    //example Text: "30/07/2022 08:32" - LEADEngine is not great with the '/' and ':' so use IronOCR
    public static OcrEngineParameters DateAndTime => new OcrEngineParameters
    {
        OcrEngine = OcrEngines.IronOCREngine,
        SearchLevel = SearchLevel.StringComparison,
        Accuracy = 0.4
    };

    //uses searchlevel and preprocessing which works best for Table Cell content
    public static OcrEngineParameters TableCell => new OcrEngineParameters
    {
        OcrEngine = OcrEngines.IronOCREngine,
        SearchLevel = SearchLevel.Words | SearchLevel.StringComparison,
        Preprocessing = new OcrPreprocessingParameters
        {
            Padding = 20,
            UseInvertModification = true,
        }
    };

    //for table cells which only contain a single line
    public static OcrEngineParameters TableCellSingleLine
    {
        get
        {
            var paras = OcrParams.TableCell;
            paras.EngineDependentParameters.Add(new IronOcrEngineParameters
            {
                PageSegmentationMode = TesseractPageSegmentationMode.SingleLine
            });
            return paras;
        }
    }
}

Last updated