Skip to content

Commit

Permalink
Fix vector resize with init for all elements (issue tesseract-ocr#3473)
Browse files Browse the repository at this point in the history
Fixes: 9710bc0
Signed-off-by: Stefan Weil <[email protected]>
  • Loading branch information
stweil committed Jun 29, 2021
1 parent ff1062d commit 27dfc33
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 11 deletions.
21 changes: 14 additions & 7 deletions src/ccmain/control.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -982,9 +982,12 @@ void Tesseract::AssignDiacriticsToOverlappingBlobs(const std::vector<C_OUTLINE *
std::vector<bool> *overlapped_any_blob,
std::vector<C_BLOB *> *target_blobs) {
std::vector<bool> blob_wanted;
word_wanted->resize(outlines.size(), false);
overlapped_any_blob->resize(outlines.size(), false);
target_blobs->resize(outlines.size(), nullptr);
word_wanted->clear();
word_wanted->resize(outlines.size());
overlapped_any_blob->clear();
overlapped_any_blob->resize(outlines.size());
target_blobs->clear();
target_blobs->resize(outlines.size());
// For each real blob, find the outlines that seriously overlap it.
// A single blob could be several merged characters, so there can be quite
// a few outlines overlapping, and the full engine needs to be used to chop
Expand All @@ -993,7 +996,8 @@ void Tesseract::AssignDiacriticsToOverlappingBlobs(const std::vector<C_OUTLINE *
for (blob_it.mark_cycle_pt(); !blob_it.cycled_list(); blob_it.forward()) {
C_BLOB *blob = blob_it.data();
const TBOX blob_box = blob->bounding_box();
blob_wanted.resize(outlines.size(), false);
blob_wanted.clear();
blob_wanted.resize(outlines.size());
int num_blob_outlines = 0;
for (unsigned i = 0; i < outlines.size(); ++i) {
if (blob_box.major_x_overlap(outlines[i]->bounding_box()) && !(*word_wanted)[i]) {
Expand Down Expand Up @@ -1032,15 +1036,18 @@ void Tesseract::AssignDiacriticsToNewBlobs(const std::vector<C_OUTLINE *> &outli
std::vector<bool> *word_wanted,
std::vector<C_BLOB *> *target_blobs) {
std::vector<bool> blob_wanted;
word_wanted->resize(outlines.size(), false);
target_blobs->resize(outlines.size(), nullptr);
word_wanted->clear();
word_wanted->resize(outlines.size());
target_blobs->clear();
target_blobs->resize(outlines.size());
// Check for outlines that need to be turned into stand-alone blobs.
for (unsigned i = 0; i < outlines.size(); ++i) {
if (outlines[i] == nullptr) {
continue;
}
// Get a set of adjacent outlines that don't overlap any existing blob.
blob_wanted.resize(outlines.size(), false);
blob_wanted.clear();
blob_wanted.resize(outlines.size());
int num_blob_outlines = 0;
TBOX total_ol_box(outlines[i]->bounding_box());
while (i < outlines.size() && outlines[i] != nullptr) {
Expand Down
3 changes: 1 addition & 2 deletions src/ccmain/linerec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,7 @@ ImageData *Tesseract::GetLineData(const TBOX &line_box, const std::vector<TBOX>
line_boxes.push_back(box);
line_texts.push_back(texts[b]);
}
std::vector<int> page_numbers;
page_numbers.resize(line_boxes.size(), applybox_page);
std::vector<int> page_numbers(line_boxes.size(), applybox_page);
image_data->AddBoxes(line_boxes, line_texts, page_numbers);
return image_data;
}
Expand Down
4 changes: 2 additions & 2 deletions src/ccmain/paragraphs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2314,14 +2314,14 @@ void CanonicalizeDetectionResults(std::vector<PARA *> *row_owners, PARA_LIST *pa
void DetectParagraphs(int debug_level, std::vector<RowInfo> *row_infos,
std::vector<PARA *> *row_owners, PARA_LIST *paragraphs,
std::vector<ParagraphModel *> *models) {
std::vector<RowScratchRegisters> rows;
ParagraphTheory theory(models);

// Initialize row_owners to be a bunch of nullptr pointers.
row_owners->clear();
row_owners->resize(row_infos->size());

// Set up row scratch registers for the main algorithm.
rows.resize(row_infos->size(), RowScratchRegisters());
std::vector<RowScratchRegisters> rows(row_infos->size());
for (unsigned i = 0; i < row_infos->size(); i++) {
rows[i].Init((*row_infos)[i]);
}
Expand Down

0 comments on commit 27dfc33

Please sign in to comment.