[Python] Tesseract OCR cannot read dotted LED digits on MAUI/Xamarin

Discussão em 'Python' iniciado por Stack, Agosto 25, 2025.

  1. Stack

    Stack Membro Participativo

    I am trying to extract numbers from dotted LED-style digits (0–9) using Tesseract OCR in a MAUI/Xamarin app on Android and iOS, fully offline. My boss wants a local solution that works on mobile phones without any cloud service.

    The problem:

    • The digits are “dotted” (like 7-segment LED panels, but only dots).
    • Tesseract works fine on normal printed text, but cannot recognize dotted digits.
    • I tried multiple Tesseract models (eng,letsgodigital, ocr, etc), but results are poor or empty.

    I thought the best approach would be to connect the dots via image processing to make solid digits before passing them to Tesseract.

    Here is my image preprocessing code (using Emgu CV / OpenCV for C#):

    public static byte[] ProcessImageForOcr(string inputImagePath)
    {
    Mat originalImage = CvInvoke.Imread(inputImagePath, ImreadModes.ColorBgr);
    if(originalImage.IsEmpty)
    throw new Exception($"Could not load image from: {inputImagePath}");

    Mat gray = new Mat();
    CvInvoke.CvtColor(originalImage, gray, ColorConversion.Bgr2Gray);

    Mat blurred = new Mat();
    CvInvoke.GaussianBlur(gray, blurred, new Size(5,5), 0);

    Mat edges = new Mat();
    CvInvoke.Canny(blurred, edges, 50, 150);

    int cropY = (int)(edges.Height * 0.25);
    Rectangle roi = new Rectangle(0, cropY, edges.Width, edges.Height - cropY);
    Mat croppedEdges = new Mat(edges, roi);

    Mat dilatedImage = new Mat();
    Mat kernel = CvInvoke.GetStructuringElement(ElementShape.Rectangle, new Size(4,4), new Point(-1,-1));
    CvInvoke.Dilate(croppedEdges, dilatedImage, kernel, new Point(-1,-1), 1, BorderType.Default, new MCvScalar(0));

    Mat finalImage = new Mat();
    CvInvoke.BitwiseNot(dilatedImage, finalImage);

    using var v = new VectorOfByte();
    if(!CvInvoke.Imencode(".png", finalImage, v))
    throw new InvalidOperationException("Failed to encode image");

    return v.ToArray();
    }


    and here are input and output images

    [​IMG]

    [​IMG]

    And here is my Tesseract usage code:

    static void tryToExtractText(string file)
    {
    Dictionary<string, string> dic = new Dictionary<string, string>
    {
    {"C:\\Temp Files\\tesseract\\models\\tessdata", "eng"},
    {"C:\\Temp Files\\tesseract\\models\\lets", "lets"},
    {"C:\\Temp Files\\tesseract\\models\\letsgodigital", "letsgodigital"},
    {"C:\\Temp Files\\tesseract\\models\\mcr", "mcr"},
    {"C:\\Temp Files\\tesseract\\models\\ocr", "ocr"}
    };

    foreach(var item in dic)
    {
    using(var engine = new TesseractEngine(item.Key, item.Value, EngineMode.Default))
    {
    engine.SetVariable("tessedit_char_whitelist", "0123456789'");
    engine.DefaultPageSegMode = PageSegMode.SingleLine;

    using(var img = Pix.LoadFromFile(file))
    using(var page = engine.Process(img))
    {
    string text = page.GetText();
    Console.WriteLine(item.Value + " result: \"{0}\"", text.Trim());
    }
    }
    }
    }


    What I tried / observed:

    • In console app: partial recognition, mostly incorrect.

    [​IMG]

    • On MAUI Android app: no text found.
    • Tried multiple Tesseract models, but no model is specifically trained for dotted LED panels.

    Goal / Question: How can I preprocess these dotted digits to make them readable by Tesseract on mobile devices (Android/iOS) offline? Are there known techniques, image processing pipelines, or lightweight ML models suitable for connecting dots / reconstructing solid digits for OCR on mobile?

    Continue reading...

Compartilhe esta Página