Skip to content

fix 添加对空文本的检查和对txt_len为0的保护 #443

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 6, 2025

Conversation

narc1ssus1
Copy link
Contributor

如果为空文本或者检测模型检测框到空区域,会报错ZeroDivisionError: float division by zero,添加对空文本的检查和对txt_len为0的保护

@narc1ssus1 narc1ssus1 closed this Jun 5, 2025
@narc1ssus1 narc1ssus1 reopened this Jun 5, 2025
@SWHL
Copy link
Member

SWHL commented Jun 5, 2025 via email

@SWHL SWHL requested a review from Copilot June 5, 2025 13:44
@SWHL SWHL added this to the v3.0.1 milestone Jun 5, 2025
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR addresses a ZeroDivisionError by adding checks for empty text and a txt_len of 0.

  • Prevents errors in OCR word box calculations by returning empty lists when no valid text is provided.
  • Protects average character width calculation by returning 0.0 when the text length is zero.
Comments suppressed due to low confidence (2)

python/rapidocr/cal_rec_boxes/main.py:80

  • [nitpick] Consider adding an inline comment explaining why empty text or a line_txt_len of 0 should result in returning empty lists to improve code clarity.
if not rec_txt or word_info.line_txt_len == 0:

python/rapidocr/cal_rec_boxes/main.py:167

  • [nitpick] Add a comment to clarify that returning 0.0 is intended to prevent division by zero when no text is present, aiding future maintainability.
if txt_len == 0:

Copy link
Member

@SWHL SWHL left a comment

Choose a reason for hiding this comment

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

LGTM

@SWHL SWHL merged commit f40638d into RapidAI:main Jun 6, 2025
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