diff --git a/src/ccstruct/boxread.cpp b/src/ccstruct/boxread.cpp index 72c645ed..5e0d7eb9 100644 --- a/src/ccstruct/boxread.cpp +++ b/src/ccstruct/boxread.cpp @@ -76,7 +76,7 @@ FILE *OpenBoxFile(const char *fname) { bool ReadAllBoxes(int target_page, bool skip_blanks, const char *filename, std::vector *boxes, std::vector *texts, std::vector *box_texts, std::vector *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"); diff --git a/src/textord/pithsync.cpp b/src/textord/pithsync.cpp index 3b56f738..868109c4 100644 --- a/src/textord/pithsync.cpp +++ b/src/textord/pithsync.cpp @@ -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 @@ -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; @@ -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; @@ -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(), @@ -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 @@ -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); } @@ -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; @@ -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 0; int32_t end_of_row; int32_t row_length = 0; @@ -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); } diff --git a/src/textord/underlin.cpp b/src/textord/underlin.cpp index 431cd498..37dc431b 100644 --- a/src/textord/underlin.cpp +++ b/src/textord/underlin.cpp @@ -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(floor(baseline->y(pos.x()) + baseline_offset + 0.5)); diff --git a/src/training/lstmtraining.cpp b/src/training/lstmtraining.cpp index d1cae301..cd3bb2e3 100644 --- a/src/training/lstmtraining.cpp +++ b/src/training/lstmtraining.cpp @@ -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) { @@ -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(FLAGS_max_image_MB) * 1048576); if (!trainer.InitCharSet(FLAGS_traineddata.c_str())) { diff --git a/src/training/unicharset/lstmtrainer.cpp b/src/training/unicharset/lstmtrainer.cpp index 6e7b780b..0f6035f6 100644 --- a/src/training/unicharset/lstmtrainer.cpp +++ b/src/training/unicharset/lstmtrainer.cpp @@ -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), diff --git a/src/training/unicharset/lstmtrainer.h b/src/training/unicharset/lstmtrainer.h index 6481a59c..1d90423a 100644 --- a/src/training/unicharset/lstmtrainer.h +++ b/src/training/unicharset/lstmtrainer.h @@ -84,7 +84,8 @@ using TestCallback = std::function