Repository navigation
No text line direction classifier in the RapidOCR language engines - #509
Merged
Merged
Conversation
RapidOCR's text line direction classifier decides for every detected line whether it is upside down, and turns it by 180 degrees if so. The classifier model (ch_ppocr_mobile_v2.0_cls) is reliable for Latin, Chinese and Japanese text. For other scripts it takes part of the upright lines for upside down. These lines are then turned, recognized as garbage and dropped because of their low score. The engines which get_engine_language() creates for Korean, Greek and Cyrillic script languages now use "Global.use_cls": False. The default engine is unchanged: it keeps the classifier. Classifier results for upright lines, RapidOCR 3.10.0 called directly on pages of 12 lines in three font sizes, as lines labelled "180" above the threshold out of all lines: English 0 of 42, German 0 of 44, Chinese 0 of 40, Japanese 1 of 43, Korean 14 of 44, Russian 3 of 45, Greek 2 of 44. Results for image-only pages of 12 lines through to_markdown(force_ocr=True), as lines found in the Markdown, identical for rapidocr 3.9.2 and 3.10.0: - Korean, "kor" or "eng+kor": 9 of 12 before, 12 of 12 now. - Russian, "rus": 8 of 12 before, 11 of 12 now. - Greek, "ell": 11 of 12 before, 12 of 12 now. - English, "eng": 12 of 12, output identical to before. The price: a page of one of these languages which is upside down as a whole is not read any more. Before, the classifier recovered 4 to 6 of its 12 lines. For Latin, Chinese and Japanese text the default engine still recovers such pages.
JorjMcKie
approved these changes
Nov 18, 2026
JorjMcKie
left a comment
Collaborator
There was a problem hiding this comment.
Thanks for this work!
Contributor
Author
|
Thanks for review! |
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.
Follow-up to #507. The engines selected through
ocr_language(Korean, Greek, Cyrillic) lose upright text lines, because RapidOCR's text line direction classifier takes them for upside down. This PR switches the classifier off for these engines. The default engine keeps it.RapidOCR classifies every detected line as "0" or "180" and turns the line if the label is "180". The classifier model (
ch_ppocr_mobile_v2.0_cls) is reliable for Latin, Chinese and Japanese text. For other scripts part of the upright lines get the label "180". They are turned, recognized as garbage and dropped because of their low score.Classifier labels for upright lines, RapidOCR 3.10.0 called directly on synthetic pages of 12 lines in three font sizes.
A higher
Cls.cls_threshor the other classifier models RapidOCR offers did not fix it for Korean, and the classifier has no language setting other thanch.Effect through
to_markdown(force_ocr=True)on image-only pages of 12 lines, as lines found in the Markdown. The numbers are the same for rapidocr 3.9.2 and 3.10.0.ocr_languagekor,eng+korrusellengThe price is that a page of one of these languages which is upside down as a whole is not read any more. Before, the classifier recovered 4 to 6 of its 12 lines, so the output was not usable either. For Latin, Chinese and Japanese text the default engine still recovers such pages.
The change is one parameter in
get_engine_language(). The tests are adjusted, and the Korean end-to-end test now expects all three Korean lines.If this is merged I will add a sentence to the "OCR Language Support" section of the PyMuPDF docs.