Skip to content

No text line direction classifier in the RapidOCR language engines - #509

Merged
veget-able merged 1 commit into
mainfrom
rapidocr-language-cls
Nov 18, 2026
Merged

veget-able merged 1 commit into
mainfrom
rapidocr-language-cls

Conversation

@veget-able

Copy link
Copy Markdown
Contributor

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.

Script Upright lines labelled "180"
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

A higher Cls.cls_thresh or the other classifier models RapidOCR offers did not fix it for Korean, and the classifier has no language setting other than ch.

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.

Page ocr_language Before After
Korean kor, eng+kor 9 of 12 12 of 12
Russian rus 8 of 12 11 of 12
Greek ell 11 of 12 12 of 12
English eng 12 of 12 12 of 12, output identical

The 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.

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 JorjMcKie left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this work!

@veget-able
veget-able merged commit ccbedfc into main Nov 18, 2026
2 of 3 checks passed
@veget-able

Copy link
Copy Markdown
Contributor Author

Thanks for review!

@veget-able
veget-able deleted the rapidocr-language-cls branch November 18, 2026 14:43
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.

2 participants