Skip to content

Commit

Permalink
Merge pull request #4174 from stweil/warnings
Browse files Browse the repository at this point in the history
Fix some compiler warnings and avoid unnecessary conversions from std::string to char pointer
  • Loading branch information
zdenop committed Dec 31, 2023
2 parents ea0b245 + 4a6efcd commit 637be53
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 26 deletions.
2 changes: 1 addition & 1 deletion src/ccstruct/boxread.cpp
Expand Up @@ -76,7 +76,7 @@ FILE *OpenBoxFile(const char *fname) {
bool ReadAllBoxes(int target_page, bool skip_blanks, const char *filename, std::vector<TBOX> *boxes,
std::vector<std::string> *texts, std::vector<std::string> *box_texts,
std::vector<int> *pages) {
std::ifstream input(BoxFileName(filename).c_str(), std::ios::in | std::ios::binary);
std::ifstream input(BoxFileName(filename), std::ios::in | std::ios::binary);
if (input.fail()) {
tprintf("Cannot read box data from '%s'.\n", BoxFileName(filename).c_str());
tprintf("Does it exists?\n");
Expand Down
20 changes: 8 additions & 12 deletions src/textord/pithsync.cpp
Expand Up @@ -316,9 +316,7 @@ double check_pitch_sync2( // find segmentation
TBOX this_box; // bounding box
TBOX next_box; // box of next blob
FPSEGPT *segpt; // segment point
double best_cost; // best path
double mean_sum; // computes result
FPCUTPT *best_end; // end of best path
int16_t best_fake; // best fake level
int16_t best_count; // no of cuts
BLOBNBOX_IT this_it; // copy iterator
Expand Down Expand Up @@ -371,8 +369,6 @@ double check_pitch_sync2( // find segmentation
}

this_it = *blob_it;
best_cost = FLT_MAX;
best_end = nullptr;
this_box = box_next(&this_it); // first box
next_box = box_next(&this_it); // second box
blob_index = 1;
Expand Down Expand Up @@ -411,7 +407,8 @@ double check_pitch_sync2( // find segmentation
}

best_fake = INT16_MAX;
best_cost = INT32_MAX;
// best path
double best_cost = INT32_MAX;
best_count = INT16_MAX;
while (x < right_edge + pitch) {
offset = x < right_edge ? right_edge - x : 0;
Expand All @@ -438,7 +435,8 @@ double check_pitch_sync2( // find segmentation
}
ASSERT_HOST(best_fake < INT16_MAX);

best_end = &cutpts[(best_left_x + best_right_x) / 2 - array_origin];
// end of best path
FPCUTPT *best_end = &cutpts[(best_left_x + best_right_x) / 2 - array_origin];
if (this_box.right() == textord_test_x && this_box.top() == textord_test_y) {
for (x = left_edge - pitch; x < right_edge + pitch; x++) {
tprintf("x=%d, C=%g, s=%g, sq=%g, prev=%d\n", x, cutpts[x - array_origin].cost_function(),
Expand Down Expand Up @@ -509,9 +507,7 @@ double check_pitch_sync3( // find segmentation
FPSEGPT *segpt; // segment point
int minindex; // next input position
int test_index; // index to mins
double best_cost; // best path
double mean_sum; // computes result
FPCUTPT *best_end; // end of best path
int16_t best_fake; // best fake level
int16_t best_count; // no of cuts
FPSEGPT_IT seg_it = seg_list; // output iterator
Expand Down Expand Up @@ -549,8 +545,6 @@ double check_pitch_sync3( // find segmentation
offset);
}

best_cost = FLT_MAX;
best_end = nullptr;
for (offset = -pitch_error, minindex = 0; offset < pitch_error; offset++, minindex++) {
mins[minindex] = projection->local_min(x + offset);
}
Expand Down Expand Up @@ -629,7 +623,8 @@ double check_pitch_sync3( // find segmentation
}

best_fake = INT16_MAX;
best_cost = INT32_MAX;
// best path
double best_cost = INT32_MAX;
best_count = INT16_MAX;
while (x < right_edge + pitch) {
offset = x < right_edge ? right_edge - x : 0;
Expand All @@ -656,7 +651,8 @@ double check_pitch_sync3( // find segmentation
}
ASSERT_HOST(best_fake < INT16_MAX);

best_end = &cutpts[(best_left_x + best_right_x) / 2 - array_origin];
// end of best path
FPCUTPT *best_end = &cutpts[(best_left_x + best_right_x) / 2 - array_origin];
// for (x=left_edge-pitch;x<right_edge+pitch;x++)
// {
// tprintf("x=%d, C=%g, s=%g, sq=%g, prev=%d\n",
Expand Down
7 changes: 3 additions & 4 deletions src/textord/tospace.cpp
Expand Up @@ -283,10 +283,8 @@ void Textord::row_spacing_stats(TO_ROW *row, GAPMAP *gapmap, int16_t block_idx,
int16_t gap_width;
int16_t real_space_threshold = 0;
int16_t max = 0;
int16_t index;
int16_t large_gap_count = 0;
bool suspected_table;
int32_t max_max_nonspace; // upper bound
bool good_block_space_estimate = block_space_gap_width > 0;
int32_t end_of_row;
int32_t row_length = 0;
Expand Down Expand Up @@ -479,11 +477,12 @@ number of samples can be taken as certain kerns.
below the threshold.
*/

max_max_nonspace = int32_t((row->space_threshold + row->kern_size) / 2);
// upper bound
int32_t max_max_nonspace = int32_t((row->space_threshold + row->kern_size) / 2);

// default
row->max_nonspace = max_max_nonspace;
for (index = 0; index <= max_max_nonspace; index++) {
for (int32_t index = 0; index <= max_max_nonspace; index++) {
if (all_gap_stats.pile_count(index) > max) {
max = all_gap_stats.pile_count(index);
}
Expand Down
6 changes: 2 additions & 4 deletions src/textord/underlin.cpp
Expand Up @@ -211,13 +211,11 @@ void vertical_cunderline_projection( // project outlines
ICOORD pos; // current point
ICOORD step; // edge step
int16_t lower_y, upper_y; // region limits
int32_t length; // of outline
int16_t stepindex; // current step
C_OUTLINE_IT out_it = outline->child();

pos = outline->start_pos();
length = outline->pathlength();
for (stepindex = 0; stepindex < length; stepindex++) {
int16_t length = outline->pathlength();
for (int16_t stepindex = 0; stepindex < length; stepindex++) {
step = outline->step(stepindex);
if (step.x() > 0) {
lower_y = static_cast<int16_t>(floor(baseline->y(pos.x()) + baseline_offset + 0.5));
Expand Down
6 changes: 3 additions & 3 deletions src/training/lstmtraining.cpp
Expand Up @@ -92,7 +92,7 @@ int main(int argc, char **argv) {
}

// Check write permissions.
std::string test_file = FLAGS_model_output.c_str();
std::string test_file = FLAGS_model_output;
test_file += "_wtest";
FILE *f = fopen(test_file.c_str(), "wb");
if (f != nullptr) {
Expand All @@ -107,10 +107,10 @@ int main(int argc, char **argv) {
}

// Setup the trainer.
std::string checkpoint_file = FLAGS_model_output.c_str();
std::string checkpoint_file = FLAGS_model_output;
checkpoint_file += "_checkpoint";
std::string checkpoint_bak = checkpoint_file + ".bak";
tesseract::LSTMTrainer trainer(FLAGS_model_output.c_str(), checkpoint_file.c_str(),
tesseract::LSTMTrainer trainer(FLAGS_model_output, checkpoint_file,
FLAGS_debug_interval,
static_cast<int64_t>(FLAGS_max_image_MB) * 1048576);
if (!trainer.InitCharSet(FLAGS_traineddata.c_str())) {
Expand Down
2 changes: 1 addition & 1 deletion src/training/unicharset/lstmtrainer.cpp
Expand Up @@ -80,7 +80,7 @@ LSTMTrainer::LSTMTrainer()
debug_interval_ = 0;
}

LSTMTrainer::LSTMTrainer(const char *model_base, const char *checkpoint_name,
LSTMTrainer::LSTMTrainer(const std::string &model_base, const std::string &checkpoint_name,
int debug_interval, int64_t max_memory)
: randomly_rotate_(false),
training_data_(max_memory),
Expand Down
3 changes: 2 additions & 1 deletion src/training/unicharset/lstmtrainer.h
Expand Up @@ -84,7 +84,8 @@ using TestCallback = std::function<std::string(int, const double *,
class TESS_UNICHARSET_TRAINING_API LSTMTrainer : public LSTMRecognizer {
public:
LSTMTrainer();
LSTMTrainer(const char *model_base, const char *checkpoint_name,
LSTMTrainer(const std::string &model_base,
const std::string &checkpoint_name,
int debug_interval, int64_t max_memory);
virtual ~LSTMTrainer();

Expand Down

0 comments on commit 637be53

Please sign in to comment.