* feat(python): draw Arabic text in vis() with khatt from the rtl extra
Recognized Arabic, Persian and Urdu text is returned in reading order,
but vis() draws it with ImageDraw.text, which only joins Arabic letters
and lays out right-to-left text when Pillow is built with Raqm. Without
it the visualization shows separate letters in reverse order, running
out of the box.
When khatt is installed (now part of the rtl extra on Python 3.10+),
right-to-left lines are shaped, start at the right edge of their box,
are centered vertically and shrink to fit the box. Other text, and RTL
text without khatt, is drawn by Pillow as before.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* style(python): ruff format the vis RTL changes
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* fix(python): let RTL text shrink below 10px to fit small boxes
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
cal_ocr_word_box returned the line's per-character probabilities, spaces
included, as the word scores, so word n got the probability of character n
of the line. Keep each word's character probabilities in
WordInfo.char_confs and score a grouped word with their mean, like the line
score; a single character keeps its own probability.
Co-authored-by: Paul Faucher <186776257+pfauch741@users.noreply.github.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
When the text classifier turns a crop by 180 degrees, recognition runs on
the rotated crop, but CalRecBoxes mapped the word boxes back as if the crop
had never been rotated. Every word/char box on an upside-down line therefore
landed on its mirror position: the first character got the box of the last.
Pass the classifier's rotation decision (same "180" label and cls_thresh
rule TextClassifier uses) to CalRecBoxes, and rotate the word boxes back
by 180 degrees within the crop before mapping them to the original image.
- TextRecognizer.get_character_dict saved the downloaded character dict to
the package models dir even when Global.model_root_dir was set, which
fails with PermissionError on a read-only install. Save it under
model_root_dir when set; fall back to DEFAULT_MODEL_PATH otherwise.
- The torch ModelLoader used cfg.model_root_dir / ... without Path(), so a
str model_root_dir raised TypeError. Wrap it in Path() like the other
engines do.
- Add tests that need no model download.
TextDetector.get_preprocess replaced limit_side_len with a hard-coded
960/1500/2000 bucket whenever limit_type was "max", so the configured
value was ignored and large images reached the detector unresized.
Pass the configured limit_side_len through for both limit types, matching
PaddleOCR DetResizeForTest.
Transformer.forward_train calls
tgt_mask = self.generate_square_subsequent_mask(tgt.shape[0], tgt.device)
but the helper only accepts sz, so the training branch of
Transformer.forward raises
TypeError: Transformer.generate_square_subsequent_mask() takes 2
positional arguments but 3 were given
The other two call sites (forward_test and forward_beam) pass one
argument and are unaffected.
Accept an optional device and forward it to the two tensor
constructors. It defaults to None, so the one-argument call sites keep
building the mask on the CPU exactly as before, and the call site that
already asks for a device now gets one.
Concurrent first calls could initialize det/cls/rec more than once. Double-check each loader under its own lock.
Fixes#724
Co-authored-by: Yuzhong Zhang <BetterAndBetterII@users.noreply.github.com>
MNNInferSession.__call__ extracted session output via
np.array(out_tensor.getData()).reshape(out_shape), which marshals
tensor contents through a slow per-element Python path. For a
PP-OCRv6 medium recognizer output (~17MB), this cost ~454ms versus
~210ms for the actual GPU inference that produced it.
Switch to getNumpyData(), which exposes the buffer directly. An
explicit copy is required since getNumpyData() returns a view into
memory owned by out_tensor; without it, out_tensor going out of
scope or being reused across shape changes caused intermittent
segfaults.
On a 39-box real-world image, total recognition time dropped from
~22s to ~8.4s. Per-crop output extraction dropped from ~454ms to
~10ms.
Fixes intermittent segfault risk from unmanaged zero-copy tensor
lifetime as a side effect.
* feat(python): support PP-OCRv6 for onnxruntime and openvino
Add PP-OCRv6 rec and det models (tiny/small/medium) for onnxruntime and openvino engines. v6 ships no cls model; reuse PP-OCRv5 cls.
- typings.py: add OCRVersion.PPOCRV6 and ModelType.TINY/SMALL/MEDIUM
- default_models.yaml: add PP-OCRv6 blocks under onnxruntime/openvino with PaddlePaddle official ModelScope URLs, verified SHA256, and dict_url (PaddleOCR dict files)
Verified end-to-end on ch_en_num.jpg with v6 small det+rec + v5 cls (onnxruntime): 18 text lines recognized correctly.
* fix(python): use uniquely-named PP-OCRv6 model URLs to avoid cache collision
PP-OCRv6 official ONNX exports are all named inference.onnx, causing det and rec models to overwrite each other in RapidOCR's cache (cache_dir/Path(url).name). Switch model_dir/dict_url to a mirror with unique filenames (ch_PP-OCRv6_<task>_<size>.onnx) under modelscope.cn/models/jaminmei/PP-OCRv6-onnx@v1.0. SHA256 unchanged (byte-identical files, renamed only).
Verified onnxruntime + openvino: no more redownload-on-collision; second run is pure cache hit.
* test(python): add PP-OCRv6 det/rec unit tests for onnxruntime and openvino
Mirror the test_ppocrv5_det/rec_mobile pattern. v6 small det on ch_en_num.jpg -> 18 boxes; v6 small rec on text_rec.jpg -> '韩国小馆'. Parametrized over the two engines v6 supports (ONNXRUNTIME, OPENVINO). Existing 100 tests unaffected (verified via collect-only).
Verified: 4 new tests pass (onnxruntime + openvino x det/rec).
* chore(python): switch PP-OCRv6 model URLs to official RapidAI/RapidOCR repo
- det/rec x tiny/small/medium now point to modelscope.cn/RapidAI/RapidOCR (official SWHL conversion, not contributor mirror)
- update SHA256 to the official files' hashes
- drop rec dict_url: official ONNX embeds the character list in metadata (session.have_key() path), matching v4/v5 onnx convention
- verified: 4 v6 unit tests pass; det benchmark Hmean identical to prior mirror-based run (0.8263/0.8492/0.8421 for tiny/small/medium)
* chore: add pyproject toml configuration
* build: migrate RapidOCR wheel packaging to pyproject.toml
- add PEP 517 setuptools build configuration
- derive package version from git tags via setuptools-scm
- move wheel model preparation into an explicit tools script
- generate MANIFEST.in for default model assets before building
- avoid importing rapidocr during package metadata generation
* ci: build release wheels from validated git tags
* build: align package runtime support with Python 3.8
- set Requires-Python to >=3.8
- remove Python 3.6 and 3.7 classifiers
- make wheel asset preparation script type hints Python 3.8 compatible
- clarify split between build-time and wheel runtime support