Skip to content

Add OCR text aggregation for multiple boxes - #4600

Open
tianrking wants to merge 1 commit into
tesseract-ocr:mainfrom
tianrking:codex/multi-region-ocr
Open

Add OCR text aggregation for multiple boxes#4600
tianrking wants to merge 1 commit into
tesseract-ocr:mainfrom
tianrking:codex/multi-region-ocr

Conversation

@tianrking

Copy link
Copy Markdown

Fixes #4366

Summary

Add TessBaseAPI::GetUTF8TextForBoxes and the matching C API entry point. The method accepts a Leptonica Boxa, reuses the configured image and OCR engine, and returns the recognized UTF-8 text in rectangle order. This gives callers a single production API for multi-region OCR instead of duplicating the SetRectangle/GetUTF8Text loop.

Validation

  • Built libtesseract with CMake (C++20, legacy engine disabled).
  • Ran a smoke program against HelloGoogle.tif and eng.traineddata; two identical boxes produced exactly two concatenated results.
  • Added TesseractTest.UTF8TextForBoxes covering the public C++ API.
  • git diff --check passes.

@codacy-production

Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

🟢 Metrics 5 complexity · 0 duplication

Metric Results
Complexity 5
Duplication 0

View in Codacy

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.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Adds C++ and C APIs for aggregating OCR text across multiple image regions.

Changes:

  • Implements ordered multi-box OCR aggregation.
  • Exposes matching public C++ and C APIs.
  • Adds a C++ unit test.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
src/api/baseapi.cpp Implements box iteration and text aggregation.
src/api/capi.cpp Adds the C API wrapper.
include/tesseract/baseapi.h Declares and documents the C++ API.
include/tesseract/capi.h Declares and documents the C API.
unittest/baseapi_test.cc Tests aggregation with repeated boxes.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread src/api/baseapi.cpp
Comment on lines +495 to +499
boxaGetBoxGeometry(const_cast<Boxa *>(boxes), i, &left, &top, &width, &height);
if (width <= 0 || height <= 0) {
continue;
}
SetRectangle(left, top, width, height);
Comment thread src/api/baseapi.cpp
Comment on lines +500 to +504
char *box_text = GetUTF8Text();
if (box_text != nullptr) {
text += box_text;
delete[] box_text;
}
Comment thread unittest/baseapi_test.cc
Comment on lines +105 to +106
boxaAddBox(boxes, boxCreate(0, 0, width, height), L_INSERT);
boxaAddBox(boxes, boxCreate(0, 0, width, height), L_INSERT);
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.

Recognize multiple rectangles on a page without clearing results inbetween

2 participants