Closed henrivain closed 10 months ago
Pull request #19 fixes this issue
Example
private async void DEMO_Recognize_AsConfigured(object sender, EventArgs e)
{
// Select image (Not important)
var path = await GetUserSelectedPath();
if (path is null)
{
return;
}
// this Tesseract is injected property
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.Auto;
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);
}
Problem
User cannot configure Tesseract parameters of the injected ITesseract api and must use underlying TessEngine api. Because of this dependency injection cannot be used when user wants to change for example
tessedit_char_whitelist
ortessedit_char_blacklist
.Current way of doing
Suggested fix
Addition to ITesseract API
Add optional configuration Property to pass into ITesseract
Changes in Tesseract.cs
Method
internal RecognizionResult Recognize(Pix pix, string tessDataFolder, string[] traineddataFileNames)
Change
To
Intended use
Set configuration func before running process