Repository navigation
feat(ocr): configurable OCR languages with Latin + Cyrillic support - #24
Closed
Venopacman wants to merge 2 commits into
Closed
Venopacman wants to merge 2 commits into
Venopacman wants to merge 2 commits into
Conversation
…vas) On an Apple Silicon Mac the screenmind process held ~8 GB: EasyOCR's gpu=True picks MPS, and PyTorch's MPS allocator kept ~7.5 GB of unified memory between frames. Moving to CPU alone did not help (peak ~8.6 GB of RAM). The cost is the CRAFT detector running over the whole image at canvas_size=2560. Memory scales with that size, while recognition still reads crops from the full-resolution image. Measured on 12 real 3024x1964 screenshots, CPU: canvas peak RAM text kept sec/frame 1920 7.7 GB 100% 7.8 1280 6.0 GB ~100% 2.5 960 4.0 GB 96% 1.9 800 3.1 GB 90% 1.7 640 2.1 GB 71% 1.1 - Use the GPU only when CUDA is available (NVIDIA users keep GPU OCR). - Pass canvas_size=800 to readtext (OCR_CANVAS_SIZE). Process footprint went from ~8.1 GB to ~1.5 GB between frames. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
OCR was hardcoded to English. Accented Latin text lost its accents
("Größe" -> "Graksa", "déploiement" -> "deploiemer") and Russian came out
as Latin junk ("Спасибо" -> "Cnachbo").
Add OCR_LANGUAGES (comma-separated EasyOCR codes, default "en", so nothing
changes unless it is set).
EasyOCR loads one recognition model per Reader, and the Cyrillic model
only pairs with English, so "en,de,ru" can't share a Reader. When a
Cyrillic code is set:
- the main Reader detects boxes once and recognizes the Latin languages,
- a second Reader (detector=False) recognizes the same boxes in Cyrillic,
- per box, the Cyrillic reading wins only if it has a Cyrillic-only letter
(б, д, и, л, я, ...) and is about as confident. Otherwise Latin stays.
This keeps English away from lookalikes: the Cyrillic model reads "MCP"
as "MCР" (Cyrillic Р) with high confidence.
- mixed-script words are normalized to their majority script.
An unsupported mix (e.g. ch_sim with de) logs a warning and falls back to
English instead of disabling OCR.
Measured on an M5 Mac, CPU, canvas_size=800, 12 real screenshots:
en 1.39 s/frame, 2.8 GB peak, 17553 chars
en,es,de,fr,ru 2.37 s/frame, 3.2 GB peak, 17556 chars
Detection sets the peak; each recognition model is 15-22 MB.
Known limits: the Cyrillic model sometimes emits a Latin "V" inside
Russian words; short words (1-2 letters) are often missed at canvas 800.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Contributor
Author
|
Same here (as !23) - I don't think you'd need multilang support right now. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Depends on #23 (same file, stacked on top of it). Until #23 merges, this PR also shows its commit. Review only the last commit,
feat(ocr): ....Problem
OCR is hardcoded to English. Accented Latin text loses its accents and Russian comes out as junk:
Die Größe der Datei überschreitetDie Graksa Datei uberschreitetLa reunión de mañanareunion mananaСпасибо, завтра посмотрюCnachbo 3aBTpaFix
New setting
OCR_LANGUAGES: comma-separated EasyOCR codes, defaulten. Nothing changes unless it's set.EasyOCR loads one recognition model per Reader, and the Cyrillic model pairs only with English. So
en,de,rucan't share one Reader. When a Cyrillic code is set:detector=False) reads the same boxes with the Cyrillic model. Detection is the expensive part, so it doesn't run twice.MCPasMCР(Cyrillic Р) with high confidence.An unsupported mix (for example
ch_simwithde) logs a warning and falls back to English instead of turning OCR off.Numbers
M5 Mac, CPU,
canvas_size=800, 12 real screenshots:OCR_LANGUAGESenen,es,de,fr,ruEnglish output doesn't change. Each recognition model is only 15–22 MB. Detection sets the peak.
Synthetic screen with one sentence per language,
en,es,de,fr,ru: accents come through (reunión,mañana,Größ,überschreitet,déploiemer,échou) and Russian reads correctly (Спасибо завтра посмотрю этот отчёт).Known limits
Vinside Russian words.mainwith the memory PR.Testing
tests/test_ocr_multilingual.py: language split, lookalike cleanup, merge rule, fallback, and the two-Reader flow. It uses fake Readers, so CI downloads no extra models.🤖 Generated with Claude Code