Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add recognizion configuration #19

Merged
merged 4 commits into from
Nov 5, 2023
Merged

Conversation

henrivain
Copy link
Owner

Add TessEngine configuration to ITesseract

Fixes issue #16

  • TessEngine can now be configured with EngineConfiguration
Action<ITessEngineConfigurable>? TesseractOcrMaui.ITesseract.EngineConfiguration { set; }

Improved code quality

Updated examples in Mainpage.xaml.cs

  • Added example of engine configuration action
private async void DEMO_Recognize_AsConfigured(object sender, EventArgs e)
{
    // Select image (Not important)
    var path = await GetUserSelectedPath();
    if (path is null)
    {
        return;
    }

    Tesseract.EngineConfiguration = (engine) =>
    {
        // Engine uses DefaultSegmentationMode, if no other is passed as method parameter.
        // If ITesseract is injected to page, this is only way of setting PageSegmentationMode.
        // PageSegmentationMode defines how ocr tries to look for text, for example singe character or single word.
        // By default uses PageSegmentationMode.Auto.
        engine.DefaultSegmentationMode = TesseractOcrMaui.Enums.PageSegmentationMode.SingleLine;
        
        engine.SetCharacterWhitelist("abcdefgh");   // These characters ocr is looking for
        engine.SetCharacterBlacklist("abc");        // These characters ocr is not looking for
        // Now ocr should be only finding characters 'defgh'
    };

    // Recognize image 
    var result = await Tesseract.RecognizeTextAsync(path);

    // For this example I reset engine configuration, because same Object is used in other examples
    Tesseract.EngineConfiguration = null;

    // Show output (Not important)
    ShowOutput("FromPath, Configured", result);

}

- Check if jpeg is loaded in Android as byte array, and notify about issue #17
- Add ITesseract TryGetTesseractLibVersion()
- Move Extension methods to better places
- Add ITesseract.EngineConfiguration action property
- Add configuration extensions to TessEngine
- Add known issue exception catch in RecognizeText(byte[] imageBytes)
- Improve MainPage examples
- Engine configuration action from Action<TessEngine> to Action<ITessEngineConfigurable>, hide implementation details
- Fix bugs in TessEngineExtensions: Remove SetEngineMode as useless, Set DefaultSegmentationMode instead
@henrivain henrivain merged commit 3f39419 into master Nov 5, 2023
@henrivain henrivain deleted the Add-Recognizion-Configuration branch January 24, 2024 16:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant