130 Commits
Author SHA1 Message Date
Mohammad EssamandClaude Opus 5.5 a538d3a75e feat(python): draw Arabic text in vis() with khatt from the rtl extra (#763)
* 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>
2026-11-04 22:01:00 +08:00
Aryan R. Ganjoo 80b427d69b fix(python): preserve resize ratios across both size limits (#761) 2026-10-25 22:47:58 +08:00
SWHL 8579a91f07 fix(inference): harden infer_argmax and add equivalence tests 2026-10-25 22:25:42 +08:00
b40c0f84b8 fix(word_box): score each word from its own characters (issue #749) (#750)
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>
2026-10-25 21:41:21 +08:00
Mohammad Hijjawi cee004f994 fix(word_box): place word boxes correctly on 180-degree rotated lines (issue #328) (#747)
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.
2026-10-25 08:17:53 +08:00
theofarouk 8ac45f4e73 fix(cls): classify the middle of long lines with the v2.0 model (#748)
Fixes #744.
2026-10-20 22:06:30 +08:00
LI 7cfd3d9ef7 fix(python): honor EXIF orientation for bytes and PIL images (#755) 2026-10-13 08:06:01 +08:00
SWHL deea2a03e6 feat: support loading raw memory image buffers with format and stride metadata 2026-10-08 11:51:27 +08:00
SWHL 75946b1d26 feat(model-routing): centralize routes in YAML and expose supported l… (#741)
* feat(model-routing): centralize routes in YAML and expose supported languages

* fix(config): correct mobile CLS architecture key casing

* docs: add Backer

* docs: add Backer

* chore: update sponsor way

* feat: add lang_mapping phrase

* refactor: change model cache name

* tests: fixed path error

* tests: add error catch

* fix(tensorrt): resolve precision against hardware capabilities
2026-10-08 10:16:32 +08:00
Rett Wilson 332b4fcc23 fix(rec): honour model_root_dir for the rec dict and str paths in torch engine (#752)
- 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.
2026-10-08 09:59:59 +08:00
Mohammad Hijjawi f65c7da00e fix(det): honour limit_side_len when limit_type is max (issue #740) (#742)
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.
2026-10-03 06:36:38 +08:00
SWHL 64b1c680be feat: support decoding images from memory addresses (issue #738) 2026-09-15 09:48:12 +08:00
SWHL 0e629c8be0 feat: validate python-bidi before initializing Arabic OCR (issue #719) 2026-08-31 10:21:10 +08:00
Yuzhong ZhangandYuzhong Zhang 486ec538d3 fix: lock lazy model load so first use constructs once (#725)
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>
2026-08-24 09:37:01 +08:00
SWHL 0ad7c04d8c perf: lazily initialize OCR models 2026-08-18 10:46:31 +08:00
SWHL 3cc33f8d54 feat: add use_preprocess_img and use_vertical_padding logic 2026-07-21 11:50:49 +08:00
SWHL c4db82f7ac test: remove invalid unit testings of tensorrt module 2026-07-09 06:10:27 +08:00
SWHL bce0c99be9 test: add PP-OCRv3 mobile unit testings 2026-07-08 21:31:33 +08:00
SWHL 370f01d0a8 feat: support PP-OCRv6 PyTor as the inference engine 2026-07-02 17:54:27 +08:00
JinmingMei 29b812fcac feat(python): add PP-OCRv6 paddle backend support (#696)
* feat(python): add PP-OCRv6 paddle backend support

- init_predictor + device_config: add PPOCRV6 to PPOCRV5 branches (PIR format, enable_new_ir/new_executor)

- have_key + get_character_list: read character_dict from inference.yml instead of always returning False

- default_models.yaml: add paddle.PP-OCRv6 det+rec (tiny/small/medium), rec has no dict_url (dict from yml)

- test_engine.py: add EngineType.PADDLE to v6 det/rec parametrize

- Verified: v6 paddle tests pass; v4/v5 paddle regression tests pass

* refactor(python): revert have_key workaround, use dict_url for paddle v6 rec

Now that dict files are available on RapidAI/RapidOCR, revert the have_key/get_character_list workaround that read character_dict from inference.yml. Add dict_url to paddle v6 rec entries pointing to the official dict files.

- paddle/main.py: have_key returns False, get_character_list returns [], remove yml_path logic

- default_models.yaml: add dict_url to paddle v6 rec (tiny/small/medium)

- init_predictor and device_config v6 branches remain (required for PIR format)
2026-06-26 08:32:26 +08:00
SWHL 4f4d675a79 chore: update files 2026-06-23 09:54:53 +08:00
SWHL 92c2d93a40 test: update PP-OCRv4/v5 unit testings 2026-06-22 22:07:04 +08:00
SWHL 1be3e8980c test: update pp-ocrv6 unit testing 2026-06-22 18:41:51 +08:00
JinmingMei 9fe06b676c feat(python): support PP-OCRv6 (onnxruntime + openvino, det + rec) (#692)
* 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)
2026-06-18 21:18:58 +08:00
SWHL 1b982078df fix: fixed issue #694 2026-06-17 10:57:41 +08:00
SWHL 2efe31f0cc fix: fixed issue #682 2026-06-11 18:54:58 +08:00
SWHL 7b2d368ac6 fix: fixed dml typo 2026-05-22 14:45:35 +08:00
SWHL 49b4fcb44c fix(cli): handle language option and empty visualization results
- pass --lang_type into RapidOCR recognition config
- skip CLI visualization when OCR or word results are empty
- validate parameter update keys before applying config updates
- add regression tests for CLI language, empty visualization, and invalid params
2026-04-27 16:51:56 +08:00
SWHL ece967983d test: add cls unit testings 2026-04-07 18:47:47 +08:00
SWHL 8ea96265b5 feat(python): add model_root_dir and download_models (API + CLI) 2026-03-19 17:27:44 +08:00
SWHL 80bbdc9615 test(tensorrt): skip TensorRT tests when not installed and exclude from parametrized suites 2026-02-26 17:34:30 +08:00
locviettriandCursor b132a915e7 feat(inference_engine): add TensorRT engine support (#623)
* feat(inference_engine): add TensorRT engine support

- Add TensorRT inference session with dynamic shape support
- Implement automatic engine building and caching per GPU architecture
- Add pre-allocated buffers with pinned memory optimization
- Support FP16/FP32/INT8 precision modes
- Add optimization profiles for det/rec/cls models
- Include comprehensive error handling and resource cleanup
- Add unit tests for TensorRT engine (skipped when unavailable)
- Add TensorRT configuration section in config.yaml

* fix(tensorrt): dynamically allocate output buffers to prevent overflow

* Update test_engine.py with TensorRT support final version

* feat(tensorrt): add model_type to engine cache key

- Include model_type in TensorRT engine cache key generation
- Ensures proper cache differentiation based on model_type

* fix(tensorrt): update maximum shape configurations for input and output tensors

- Increased max_shape values in config.yaml and engine_builder.py to 2048 for both detection and recognition tasks.
- Updated default maximum shapes in memory_utils.py to reflect the new limits for input and output buffers.

* feat(tensorrt): implement square input handling for MULTI models

- Added functionality to check if the model requires square input based on configuration.
- Implemented padding of input to square shape and cropping of output back to original dimensions.
- Introduced methods to determine maximum profile size and handle square input requirements for TensorRT inference.

---------

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-02-05 08:09:21 +08:00
SWHL 3a4a91020b test(mnn): add mnn unit testings 2026-01-28 22:18:58 +08:00
SWHL 5cd7de1e47 refactor: refactor paddle inference code (#622)
* refactor: refactor paddle inference code

* fix(paddle): correct typo and improve device env setup
2026-01-05 21:19:25 +08:00
SWHL 8487133fc5 feat: update five multi language files (#619)
* feat: update five multi language files

* feat(rec): enable RTL text display for Arabic

* test(rec): add arabic, cyrillic, devanagari, ta and te unit testings

* test(rec): remove duplicate cyrillic unit testing

* feat(rec): update url to v3.5.0
2025-12-26 21:24:58 +08:00
SWHL 787819457f fix: fixed issue #566 (#573)
* chore: update files

* chore: update files

* chore: refacter torch config

* chore: refacter torch infersession

* chore: refacter torch infersession

* test: change image url from github to modelscope
2025-11-07 20:00:33 +08:00
SWHL 13fb8cc8db fix: fixed issue #542 (#564)
* fix: fixed issue #542

* test: update the image of the test cls

* test: update the ground truth of the test cls image
2025-10-11 21:40:00 +08:00
SWHL 32dad48ebb fix: fixed issue #555
* fix: fixed issue #555

* chore: refactor code

* chore: refactor code

* chore: refactor code

* chore: refactor code

* chore: refactor code
2025-09-30 17:44:20 +08:00
SWHL 017b8fd5c7 feat: add en/el/th ppocr_v5_rec_mobile paddle/onnx/openvino (#546)
* feat: add en/el/th ppocr_v5_rec_mobile paddle/onnx/openvino

* test: change to a more secure code
2025-09-06 17:50:05 +08:00
SWHL 336e6424a5 fix: fixed issue #531 2025-09-03 21:58:15 +08:00
SWHL 480abaf854 chore: remove rapidocr_paddle/torch/onnxruntime/openvion code 2025-07-29 08:08:48 +08:00
SWHL 66e00f4beb feat(rapidocr): update ppocrv5 minor language config and unit testings 2025-07-27 18:02:19 +08:00
SWHL c50038bc1e feat(rapidocr): add korean ppocrv5 config and update uniting testing 2025-07-27 17:54:35 +08:00
SWHL 78b39ca378 feat(rapidocr): support ppocr v5 minor language model(korean / latin / eslav) (#516)
* feat(rapidocr): add korean ppocrv5 config and update uniting testing

* feat: support latin ppocrv5 model(paddle/ort)

* feat: support eslav ppocrv5 model(paddle/ort)

* feat(rapidocr): update model version
2025-07-27 17:51:02 +08:00
SWHL 4c4bcab0be feat(rapidocr): add font_path and lang_type parameter of cli 2025-07-27 09:15:12 +08:00
SWHL 20cbc41e36 test: add to_json and to_markdown unit testings 2025-07-27 08:52:35 +08:00
SWHL 1797850c15 feat(rapidocr): add ppocr v5 torch version (#511)
* feat: support torch ppocrv5 det

* feat: support torch ppocrv5 rec

* chore: update files

* chore: update files

* test: add ppocrv5 torch unit testings

* fix: fix typos
2025-07-23 22:08:31 +08:00
SWHL 0b2d7f0d24 test: update unit testing when adjusting the format of returning word box 2025-06-18 08:22:56 +08:00
SWHL 0190646256 fix(rapidoicr): fixed issue #446 (#453)
* fix(rapidoicr): fixed issue #446

* test(rapidocr): remove pdb code
2025-06-10 21:45:15 +08:00
SWHL 41d5824e13 feat: adapt PR #451
* feat: adapt CANN of onnxruntime (PR #428)

* chore: fix typos

* docs: update README

* fix(rapidocr): fixed issue #438

* chore: update files

* chore: update files

* chore: update files
2025-06-10 20:36:41 +08:00