Skip to content
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

RFC: Improve positioning of symbol bounding boxes #3787

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Improve flexibility of MoveAndClipBox
p12tic committed Apr 10, 2022
commit dbb2adbd23555cfc408958efabecbb9148da1275
16 changes: 8 additions & 8 deletions src/ccstruct/pageres.cpp
Original file line number Diff line number Diff line change
@@ -1349,11 +1349,11 @@ static TBOX ComputeWordBounds(const tesseract::PointerVector<WERD_RES> &words,
return clipped_box;
}

// Helper moves the blob from src to dest. If it isn't contained by clip_box,
// the blob is replaced by a fake that is contained.
static TBOX MoveAndClipBlob(C_BLOB_IT *src_it, C_BLOB_IT *dest_it,
const TBOX &clip_box) {
C_BLOB *src_blob = src_it->extract();
// Helper moves the src_blob to dest. If it isn't contained by clip_box,
// the blob is replaced by a fake that is contained. The helper takes ownership
// of the blob.
static TBOX ClipAndAddBlob(C_BLOB *src_blob, C_BLOB_IT *dest_it,
const TBOX &clip_box) {
TBOX box = src_blob->bounding_box();
if (!clip_box.contains(box)) {
int left =
@@ -1447,17 +1447,17 @@ void PAGE_RES_IT::ReplaceCurrentWord(
// Add the blobs up to end_x.
while (!src_b_it.empty() &&
src_b_it.data()->bounding_box().x_middle() < end_x) {
blob_box += MoveAndClipBlob(&src_b_it, &dest_it, clip_box);
blob_box += ClipAndAddBlob(src_b_it.extract(), &dest_it, clip_box);
src_b_it.forward();
}
while (!rej_b_it.empty() &&
rej_b_it.data()->bounding_box().x_middle() < end_x) {
blob_box += MoveAndClipBlob(&rej_b_it, &dest_it, clip_box);
blob_box += ClipAndAddBlob(rej_b_it.extract(), &dest_it, clip_box);
rej_b_it.forward();
}
if (blob_box.null_box()) {
// Use the original box as a back-up.
blob_box = MoveAndClipBlob(&fake_b_it, &dest_it, clip_box);
blob_box = ClipAndAddBlob(fake_b_it.extract(), &dest_it, clip_box);
}
box_word->InsertBox(i, blob_box);
}