Skip to content

Commit

Permalink
fix uninitialized variables in wordstrboxrenderer and lstmboxrenderer;
Browse files Browse the repository at this point in the history
CID 1399132, 1399134, 1399135, 1399137, 1399140, 1399141, 1399142
  • Loading branch information
zdenop committed Mar 31, 2019
1 parent 497d1c5 commit f47c7c9
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 24 deletions.
21 changes: 11 additions & 10 deletions src/api/lstmboxrenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Description: Renderer for creating box file for LSTM training.
* based on the tsv renderer.
*
* (C) Copyright 2006, Google Inc.
* (C) Copyright 2019, Google Inc.
** Licensed under the Apache License, Version 2.0 (the "License");
** you may not use this file except in compliance with the License.
** You may obtain a copy of the License at
Expand Down Expand Up @@ -35,14 +35,13 @@ static void AddBoxToLSTM(int right, int bottom, int top, int image_height,
text->add_str_int(" ", page_num);
}

char* TessBaseAPI::GetLSTMBoxText(int page_number) {
char* TessBaseAPI::GetLSTMBoxText(int page_number=0) {
if (tesseract_ == nullptr || (page_res_ == nullptr && Recognize(nullptr) < 0))
return nullptr;

STRING lstm_box_str("");
int page_num = page_number;
bool first_word = true;
int left, top, right, bottom;
int left = 0, top = 0, right = 0, bottom = 0;

LTRResultIterator* res_it = GetLTRIterator();
while (!res_it->Empty(RIL_BLOCK)) {
Expand All @@ -54,14 +53,14 @@ char* TessBaseAPI::GetLSTMBoxText(int page_number) {
if (!(res_it->IsAtBeginningOf(RIL_TEXTLINE))) {
if (res_it->IsAtBeginningOf(RIL_WORD)) {
lstm_box_str.add_str_int(" ", left);
AddBoxToLSTM(right, bottom, top, image_height_, page_num,
AddBoxToLSTM(right, bottom, top, image_height_, page_number,
&lstm_box_str);
lstm_box_str += "\n"; // end of row for word
} // word
} else {
if (res_it->IsAtBeginningOf(RIL_TEXTLINE)) {
lstm_box_str.add_str_int("\t ", left);
AddBoxToLSTM(right, bottom, top, image_height_, page_num,
AddBoxToLSTM(right, bottom, top, image_height_, page_number,
&lstm_box_str);
lstm_box_str += "\n"; // end of row for line
} // line
Expand All @@ -76,12 +75,14 @@ char* TessBaseAPI::GetLSTMBoxText(int page_number) {
res_it->Next(RIL_SYMBOL);
} while (!res_it->Empty(RIL_BLOCK) && !res_it->IsAtBeginningOf(RIL_SYMBOL));
lstm_box_str.add_str_int(" ", left);
AddBoxToLSTM(right, bottom, top, image_height_, page_num, &lstm_box_str);
AddBoxToLSTM(right, bottom, top, image_height_, page_number, &lstm_box_str);
lstm_box_str += "\n"; // end of row for symbol
}
lstm_box_str.add_str_int("\t ", left);
AddBoxToLSTM(right, bottom, top, image_height_, page_num, &lstm_box_str);
lstm_box_str += "\n"; // end of PAGE
if (!first_word) { // if first_word is true => empty page
lstm_box_str.add_str_int("\t ", left);
AddBoxToLSTM(right, bottom, top, image_height_, page_number, &lstm_box_str);
lstm_box_str += "\n"; // end of PAGE
}
char* ret = new char[lstm_box_str.length() + 1];
strcpy(ret, lstm_box_str.string());
delete res_it;
Expand Down
31 changes: 17 additions & 14 deletions src/api/wordstrboxrenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Description: Renderer for creating box file with WordStr strings.
* based on the tsv renderer.
*
* (C) Copyright 2006, Google Inc.
* (C) Copyright 2019, Google Inc.
** Licensed under the Apache License, Version 2.0 (the "License");
** you may not use this file except in compliance with the License.
** You may obtain a copy of the License at
Expand All @@ -28,13 +28,13 @@ namespace tesseract {
* file. Returned string must be freed with the delete [] operator.
*/

char* TessBaseAPI::GetWordStrBoxText(int page_number) {
char* TessBaseAPI::GetWordStrBoxText(int page_number=0) {
if (tesseract_ == nullptr || (page_res_ == nullptr && Recognize(nullptr) < 0))
return nullptr;

STRING wordstr_box_str("");
int left, top, right, bottom;
int page_num = page_number;
int left = 0, top = 0, right = 0, bottom = 0;

bool first_line = true;

LTRResultIterator* res_it = GetLTRIterator();
Expand All @@ -44,24 +44,24 @@ char* TessBaseAPI::GetWordStrBoxText(int page_number) {
continue;
}

// Use bounding box for whole line for WordStr
res_it->BoundingBox(RIL_TEXTLINE, &left, &top, &right, &bottom);
if (res_it->IsAtBeginningOf(RIL_TEXTLINE)) {
if (!first_line) {
wordstr_box_str.add_str_int("\n\t ", right + 1);
wordstr_box_str.add_str_int(" ", image_height_ - bottom);
wordstr_box_str.add_str_int(" ", right + 5);
wordstr_box_str.add_str_int(" ", image_height_ - top);
wordstr_box_str.add_str_int(" ", page_num); // row for tab for EOL
wordstr_box_str.add_str_int(" ", page_number); // row for tab for EOL
wordstr_box_str += "\n";
} else {
first_line = false;
}
// Use bounding box for whole line for WordStr
res_it->BoundingBox(RIL_TEXTLINE, &left, &top, &right, &bottom);
wordstr_box_str.add_str_int("WordStr ", left);
wordstr_box_str.add_str_int(" ", image_height_ - bottom);
wordstr_box_str.add_str_int(" ", right);
wordstr_box_str.add_str_int(" ", image_height_ - top);
wordstr_box_str.add_str_int(" ", page_num); // word
wordstr_box_str.add_str_int(" ", page_number); // word
wordstr_box_str += " #";
}
do {
Expand All @@ -71,12 +71,15 @@ char* TessBaseAPI::GetWordStrBoxText(int page_number) {
res_it->Next(RIL_WORD);
} while (!res_it->Empty(RIL_BLOCK) && !res_it->IsAtBeginningOf(RIL_WORD));
}
wordstr_box_str.add_str_int("\n\t ", right + 1);
wordstr_box_str.add_str_int(" ", image_height_ - bottom);
wordstr_box_str.add_str_int(" ", right + 5);
wordstr_box_str.add_str_int(" ", image_height_ - top);
wordstr_box_str.add_str_int(" ", page_num); // row for tab for EOL
wordstr_box_str += "\n";

if (left != 0 && top != 0 && right != 0 && bottom != 0) {
wordstr_box_str.add_str_int("\n\t ", right + 1);
wordstr_box_str.add_str_int(" ", image_height_ - bottom);
wordstr_box_str.add_str_int(" ", right + 5);
wordstr_box_str.add_str_int(" ", image_height_ - top);
wordstr_box_str.add_str_int(" ", page_number); // row for tab for EOL
wordstr_box_str += "\n";
}
char* ret = new char[wordstr_box_str.length() + 1];
strcpy(ret, wordstr_box_str.string());
delete res_it;
Expand Down

0 comments on commit f47c7c9

Please sign in to comment.