Add OCR text aggregation for multiple boxes - #4600
Open
tianrking wants to merge 1 commit into
Open
Conversation
Up to standards ✅🟢 Issues
|
| Metric | Results |
|---|---|
| Complexity | 5 |
| 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.
There was a problem hiding this comment.
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 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 on lines
+500
to
+504
| char *box_text = GetUTF8Text(); | ||
| if (box_text != nullptr) { | ||
| text += box_text; | ||
| delete[] box_text; | ||
| } |
Comment on lines
+105
to
+106
| boxaAddBox(boxes, boxCreate(0, 0, width, height), L_INSERT); | ||
| boxaAddBox(boxes, boxCreate(0, 0, width, height), L_INSERT); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #4366
Summary
Add
TessBaseAPI::GetUTF8TextForBoxesand the matching C API entry point. The method accepts a LeptonicaBoxa, 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
libtesseractwith CMake (C++20, legacy engine disabled).HelloGoogle.tifandeng.traineddata; two identical boxes produced exactly two concatenated results.TesseractTest.UTF8TextForBoxescovering the public C++ API.git diff --checkpasses.