Skip to content

Address inability to OCR outside Latin/CJK#427

Open
JorjMcKie wants to merge 1 commit into
mainfrom
immunize-ocr
Open

Address inability to OCR outside Latin/CJK#427
JorjMcKie wants to merge 1 commit into
mainfrom
immunize-ocr

Conversation

@JorjMcKie

Copy link
Copy Markdown
Collaborator

Out OCR support is restricted to (extended) Latin and CJK - for a number of reasons. This change tries to ensure that no OCR is ever recommended nor tried for pages that contain Unicodes outside these ranges.

  • If analyze_page detects "unsafe" characters, it will not recommend OCR
  • If an OCR plugin (RapidOCR and friends) either detects legible but unsafe Unicodes or recognizes unsafe Unicodes, the page will not be OCR'd.

Out OCR support is restricted to (extended) Latin and CJK - for a number of reasons.
This change tries to ensure that no OCR is ever recommended nor tried for pages that contain Unicodes outside these ranges.

* If analyze_page detects "unsafe" characters, it will not recommend OCR
* If an OCR plugin (RapidOCR and friends) either detects legible but unsafe Unicodes or recognizes unsafe Unicodes, the page will not be OCR'd.
Comment thread src/ocr/analyze_page.py
BLOCK_VECTOR = mupdf.FZ_STEXT_BLOCK_VECTOR
# Thresholds
BAD_CHAR_THRESHOLD = 0.05 # >=5% bad chars suggests OCR
BAD_CHAR_THRESHOLD = 0.10 # >=10% bad chars suggests OCR

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.

This change seems unrelated to what this commit is about. Could we move it into a separate commit/pr?

Comment thread src/ocr/analyze_page.py

# --- final OCR decision ---
if unsafe_text_spans:
# If there are unsafe text spans, we recommend OCR.

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.

Should this comment say "we do not recommend OCR"?

Comment thread src/ocr/analyze_page.py
Comment on lines -324 to +343
or chars_bad / chars_total > BAD_CHAR_THRESHOLD
or bad_areas / txt_area > BAD_CHAR_THRESHOLD
or (chars_bad / chars_total > BAD_CHAR_THRESHOLD
and bad_areas / txt_area > BAD_CHAR_THRESHOLD)

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.

Can this be moved to a separate commit/pr?

Comment thread src/ocr/paddleocr_api.py
Comment on lines +123 to +128
if any(contains_unsafe(text) for _, text, _ in result):
# If any recognized text contains unsafe characters, we skip OCR
# entirely. This is because we have no way yet to make correct
# insertions of such text into the page.
return

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.

Is this checking for bad characters in the output of the ocr engine? If so the comment seems misleading?
Is there a still a risk of crashing at this stage?

Comment thread src/ocr/rapidocr_api.py
Comment on lines +123 to +128
if any(contains_unsafe(text) for _, text, _ in result):
# If any recognized text contains unsafe characters, we skip OCR
# entirely. This is because we have no way yet to make correct
# insertions of such text into the page.
return

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.

Similar question to above, about why we are worrying about bad characters in the output from the ocr engine.

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