Skip to content

fix(ocr): support Japanese kana word boxes#5168

Open
Ikwus wants to merge 1 commit into
PaddlePaddle:release/3.7from
Ikwus:codex/japanese-kana-word-box
Open

fix(ocr): support Japanese kana word boxes#5168
Ikwus wants to merge 1 commit into
PaddlePaddle:release/3.7from
Ikwus:codex/japanese-kana-word-box

Conversation

@Ikwus

@Ikwus Ikwus commented Jun 28, 2026

Copy link
Copy Markdown

Summary

Fix Japanese kana word-box grouping when OCR is run with return_word_box=True.

Japanese Hiragana, Katakana, the prolonged sound mark, and halfwidth Katakana are now treated as character-level word-box characters while keeping the existing cn state name for backward compatibility.

Fixes PaddlePaddle/PaddleOCR#18222

Prior Art / Search

I searched the PaddleOCR docs, issues, and discussions. I found related return_word_box reports and fixes for accented Latin text and Arabic text, but I did not find a Japanese kana-specific report.

This PR is still worth tracking separately because Japanese kana currently gets phrase-level boxes while Japanese/Chinese Han characters already get character-level boxes. That makes Japanese mixed-script output inconsistent for downstream consumers of text_word and text_word_boxes.

Related context:

Root Cause

BaseRecLabelDecode.get_word_info() only classified CJK Unified Ideographs (\u4e00-\u9fff) as cn. Japanese kana fell into symbol.

cal_ocr_word_box() expands state == "cn" groups to character-level boxes, but non-cn groups are returned as one grouped box. Therefore kana-only Japanese text could be returned as a single phrase-level word box, while Han characters already returned character-level boxes.

Fix

Add a small kana classifier for:

  • Hiragana
  • Katakana, including the prolonged sound mark
  • Halfwidth Katakana

Then route those characters to the existing cn state so the downstream word-box logic keeps returning character-level boxes without renaming or changing the public state value.

Reproduction

A synthetic image is enough; no real document image is required.

from PIL import Image, ImageDraw, ImageFont

font = ImageFont.truetype("/usr/share/fonts/opentype/noto/NotoSansCJK-Medium.ttc", 48)
text = "りんごジュースストレート"
img = Image.new("RGB", (760, 160), "white")
draw = ImageDraw.Draw(img)
draw.rectangle((16, 16, 744, 144), outline=(180, 180, 180), width=2)
draw.text((48, 50), text, fill="black", font=font)
img.save("paddlex_kana_word_box_repro.png")

Observed grouping with PP-OCRv6 medium OCR and return_word_box=True:

Pattern Before After
りんごジュースストレート 1 grouped box 12 character boxes
東京都中央区請求書 9 character boxes 9 character boxes
東京りんごジュース 3 boxes: , , りんごジュース 9 character boxes

I checked the same synthetic patterns with Noto Sans CJK JP Medium, Noto Sans CJK JP Bold, and Noto Serif CJK JP SemiBold.

Tests

There was no existing unit test file for BaseRecLabelDecode.get_word_info() or return_word_box word grouping in PaddleX, so this PR adds focused unit coverage under tests/.

  • python -m py_compile paddlex/inference/models/text_recognition/processors.py tests/test_text_recognition_word_info.py
  • python -m pytest tests/test_text_recognition_word_info.py
  • Manual PP-OCRv6 medium OCR check on synthetic rendered Japanese test patterns.

@CLAassistant

CLAassistant commented Jun 28, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@paddle-bot

paddle-bot Bot commented Jul 14, 2026

Copy link
Copy Markdown

Thanks for your contribution!

@paddle-bot paddle-bot Bot added the contributor External developers label Jul 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

contributor External developers

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Japanese kana text is returned as a single word box with return_word_box=True

2 participants