Reject non-text sparse partitions - #4603
Conversation
Up to standards ✅🟢 Issues
|
| Metric | Results |
|---|---|
| Complexity | 0 |
| Duplication | 0 |
NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.
9ad0ef6 to
117e158
Compare
|
|
||
| namespace tesseract { | ||
|
|
||
| namespace { |
There was a problem hiding this comment.
It’s an anonymous namespace, added to give ExtractedBlockCount internal linkage. The function is only used by the tests in this file, so it shouldn’t be exposed as an external symbol in the tesseract namespace.
There was a problem hiding this comment.
Pull request overview
Refines sparse partition extraction to reject unknown multi-blob regions explicitly classified as non-text, preventing pathological OCR slowdowns.
Changes:
- Excludes
BRT_UNKNOWNpartitions withBTFT_NONTEXTflow. - Adds focused tests covering retained and rejected partition types.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
src/textord/colpartitiongrid.cpp |
Tightens sparse partition acceptance logic. |
unittest/colpartition_test.cc |
Tests the updated extraction policy. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Summary
Refine sparse partition extraction so that a multi-blob
BRT_UNKNOWNpartition is accepted only when its text flow is notBTFT_NONTEXT.Sparse segmentation can classify background texture as unknown partitions with an explicit non-text flow. The extractor previously accepted every multi-blob unknown partition, turning those regions into separate text blocks and making pathological inputs extremely expensive to process.
All text region types remain accepted regardless of flow. Multi-blob unknown partitions with other flow values also remain accepted.
Related to #4430.
Performance
GCC 15.2 RelWithDebInfo build, with OEM 3, PSM 11 and
OMP_THREAD_LIMIT=1:input-4267x3200.pngpage.pngThe minimal repro changes from 1,681 extracted blocks and words to 48, and from 6,723 bytes of OCR text to 191 bytes. The removed output came from unknown partitions whose flow was explicitly classified as non-text.
The
mainrun ("before") for the #4430 image did not complete within 300 seconds, so it has no completed OCR output for comparison.input-4267x3200.png
background-tile-16.png
Validation
mainacross 14 runs covering seven English, Hebrew and Arabic test images.BTFT_NONTEXTis a segmentation heuristic, so weak real text over photos or textures could be excluded if it is classified as bothBRT_UNKNOWNandBTFT_NONTEXT. The focused tests and available smoke set showed no regression but broader scene-text corpus evaluation would provide additional confidence.