diff --git a/src/ccmain/applybox.cpp b/src/ccmain/applybox.cpp index e50bda50..452da1a4 100644 --- a/src/ccmain/applybox.cpp +++ b/src/ccmain/applybox.cpp @@ -26,6 +26,7 @@ #include #include "pageres.h" #include "tesseractclass.h" +#include "tesserrstream.h" // for tesserr #include "unicharset.h" #ifndef DISABLED_LEGACY_ENGINE @@ -652,9 +653,10 @@ void Tesseract::SearchForText(const std::vector *choices, in if (choices_pos + length == choices_length && text_index + 1 == target_text.size()) { // This is a complete match. If the rating is good record a new best. if (applybox_debug > 2) { - tprintf("Complete match, rating = %g, best=%g, seglength=%zu, best=%zu\n", - rating + choice_rating, *best_rating, segmentation->size(), - best_segmentation->size()); + tesserr << "Complete match, rating = " << rating + choice_rating + << ", best=" << *best_rating + << ", seglength=" << segmentation->size() + << ", best=" << best_segmentation->size() << '\n'; } if (best_segmentation->empty() || rating + choice_rating < *best_rating) { *best_segmentation = *segmentation; diff --git a/src/ccmain/paragraphs.cpp b/src/ccmain/paragraphs.cpp index ed05b73f..bf802a61 100644 --- a/src/ccmain/paragraphs.cpp +++ b/src/ccmain/paragraphs.cpp @@ -31,6 +31,7 @@ #include "ratngs.h" // for WERD_CHOICE #include "rect.h" // for TBOX #include "statistc.h" // for STATS +#include "tesserrstream.h" // for tesserr #include "tprintf.h" // for tprintf #include "unicharset.h" // for UNICHARSET #include "werd.h" // for WERD, W_REP_CHAR @@ -74,8 +75,8 @@ static bool AcceptableRowArgs(int debug_level, int min_num_rows, const char *fun const std::vector *rows, int row_start, int row_end) { if (row_start < 0 || static_cast(row_end) > rows->size() || row_start > row_end) { - tprintf("Invalid arguments rows[%d, %d) while rows is of size %zu.\n", row_start, row_end, - rows->size()); + tesserr << "Invalid arguments rows[" << row_start << ", " << row_end + << ") while rows is of size " << rows->size() << ".\n"; return false; } if (row_end - row_start < min_num_rows) { @@ -915,10 +916,9 @@ struct GeometricClassifierState { tolerance = InterwordSpace(*r, r_start, r_end); CalculateTabStops(r, r_start, r_end, tolerance, &left_tabs, &right_tabs); if (debug_level >= 3) { - tprintf( - "Geometry: TabStop cluster tolerance = %d; " - "%zu left tabs; %zu right tabs\n", - tolerance, left_tabs.size(), right_tabs.size()); + tesserr << "Geometry: TabStop cluster tolerance = " << tolerance << "; " + << left_tabs.size() << " left tabs; " + << right_tabs.size() << " right tabs\n"; } ltr = (*r)[r_start].ri_->ltr; } diff --git a/src/ccstruct/detlinefit.cpp b/src/ccstruct/detlinefit.cpp index d100aa50..fbbc9c47 100644 --- a/src/ccstruct/detlinefit.cpp +++ b/src/ccstruct/detlinefit.cpp @@ -17,9 +17,9 @@ /////////////////////////////////////////////////////////////////////// #include "detlinefit.h" -#include "helpers.h" // for IntCastRounded +#include "helpers.h" // for IntCastRounded #include "statistc.h" -#include "tprintf.h" +#include "tesserrstream.h" // for tesserr #include #include // for FLT_MAX @@ -143,13 +143,17 @@ double DetLineFit::ConstrainedFit(const FCOORD &direction, double min_dist, doub std::nth_element(distances_.begin(), distances_.begin() + median_index, distances_.end()); *line_pt = distances_[median_index].data(); if (debug) { - tprintf("Constrained fit to dir %g, %g = %d, %d :%zu distances:\n", direction.x(), direction.y(), - line_pt->x(), line_pt->y(), distances_.size()); + tesserr << "Constrained fit to dir " << direction.x() << ", " + << direction.y() << " = " + << line_pt->x() << ", " << line_pt->y() + << " :" << distances_.size() << " distances:\n"; for (unsigned i = 0; i < distances_.size(); ++i) { - tprintf("%d: %d, %d -> %g\n", i, distances_[i].data().x(), distances_[i].data().y(), - distances_[i].key()); + tesserr << i << ": " + << distances_[i].data().x() << ", " + << distances_[i].data().y() << " -> " + << distances_[i].key() << '\n'; } - tprintf("Result = %zu\n", median_index); + tesserr << "Result = " << median_index << '\n'; } // Center distances on the fitted point. double dist_origin = direction * *line_pt; diff --git a/src/ccstruct/imagedata.cpp b/src/ccstruct/imagedata.cpp index 10de5fbe..03c5049c 100644 --- a/src/ccstruct/imagedata.cpp +++ b/src/ccstruct/imagedata.cpp @@ -27,6 +27,7 @@ #include "rect.h" // for TBOX #include "scrollview.h" // for ScrollView, ScrollView::CYAN, ScrollView::NONE #include "tprintf.h" // for tprintf +#include "tesserrstream.h" // for tesserr #include "helpers.h" // for IntCastRounded, TRand, ClipToRange, Modulo #include "serialis.h" // for TFile @@ -618,9 +619,10 @@ bool DocumentData::ReCachePages() { pages_.clear(); } else if (loaded_pages > 1) { // Avoid lots of messages for training with single line images. - tprintf("Loaded %zu/%d lines (%d-%zu) of document %s\n", pages_.size(), - loaded_pages, pages_offset_ + 1, pages_offset_ + pages_.size(), - document_name_.c_str()); + tesserr << "Loaded " << pages_.size() << '/' << loaded_pages << " lines (" + << pages_offset_ + 1 << '-' + << pages_offset_ + pages_.size() << ") of document " + << document_name_ << '\n'; } set_total_pages(loaded_pages); return !pages_.empty(); diff --git a/src/classify/shapetable.h b/src/classify/shapetable.h index 0d2cd41c..8497b786 100644 --- a/src/classify/shapetable.h +++ b/src/classify/shapetable.h @@ -26,6 +26,7 @@ #include "fontinfo.h" #include "genericheap.h" #include "intmatcher.h" +#include "tesserrstream.h" // for tesserr namespace tesseract { @@ -41,10 +42,10 @@ struct UnicharRating { // Print debug info. void Print() const { - tprintf( - "Unichar-id=%d, rating=%g, adapted=%d, config=%d, misses=%u," - " %zu fonts\n", - unichar_id, static_cast(rating), adapted, config, feature_misses, fonts.size()); + tesserr << "Unichar-id=" << unichar_id << ", rating=" << rating + << ", adapted=" << adapted << ", config=" << config + << ", misses=" << feature_misses << ", " + << fonts.size() << " fonts\n"; } // Helper function to get the index of the first result with the required diff --git a/src/dict/dict.cpp b/src/dict/dict.cpp index be3cc137..2dc5dcb7 100644 --- a/src/dict/dict.cpp +++ b/src/dict/dict.cpp @@ -18,6 +18,7 @@ #include "dict.h" +#include "tesserrstream.h" // for tesserr #include "tprintf.h" #include @@ -410,10 +411,10 @@ int Dict::def_letter_is_okay(void *void_dawg_args, const UNICHARSET &unicharset, ASSERT_HOST(unicharset.contains_unichar_id(unichar_id)); if (dawg_debug_level >= 3) { - tprintf( - "def_letter_is_okay: current unichar=%s word_end=%d" - " num active dawgs=%zu\n", - getUnicharset().debug_str(unichar_id).c_str(), word_end, dawg_args->active_dawgs->size()); + tesserr << "def_letter_is_okay: current unichar=" + << getUnicharset().debug_str(unichar_id) + << " word_end=" << word_end + << " num active dawgs=" << dawg_args->active_dawgs->size() << '\n'; } // Do not accept words that contain kPatternUnicharID. diff --git a/src/lstm/series.cpp b/src/lstm/series.cpp index 99069861..25b0d274 100644 --- a/src/lstm/series.cpp +++ b/src/lstm/series.cpp @@ -20,6 +20,7 @@ #include "fullyconnected.h" #include "networkscratch.h" #include "scrollview.h" +#include "tesserrstream.h" // for tesserr #include "tprintf.h" namespace tesseract { @@ -164,7 +165,8 @@ void Series::SplitAt(unsigned last_start, Series **start, Series **end) { *start = nullptr; *end = nullptr; if (last_start >= stack_.size()) { - tprintf("Invalid split index %u must be in range [0,%zu]!\n", last_start, stack_.size() - 1); + tesserr << "Invalid split index " << last_start + << " must be in range [0," << stack_.size() - 1 << "]!\n"; return; } auto *master_series = new Series("MasterSeries"); diff --git a/src/textord/baselinedetect.cpp b/src/textord/baselinedetect.cpp index 82df673b..dea18735 100644 --- a/src/textord/baselinedetect.cpp +++ b/src/textord/baselinedetect.cpp @@ -34,6 +34,7 @@ #include "helpers.h" #include "linlsq.h" #include "makerow.h" +#include "tesserrstream.h" // for tesserr #include "textord.h" #include "tprintf.h" #include "underlin.h" @@ -671,9 +672,10 @@ bool BaselineBlock::ComputeLineSpacing() { } } if (debug_level_ > 0) { - tprintf("Spacing %g, in %zu rows, %d gaps fitted out of %d non-trivial\n", - line_spacing_, row_positions.size(), fitting_gaps, - non_trivial_gaps); + tesserr << "Spacing " << line_spacing_ << ", in " + << row_positions.size() << " rows, " + << fitting_gaps << " gaps fitted out of " + << non_trivial_gaps << " non-trivial\n"; } return fitting_gaps > non_trivial_gaps * kMinFittingLinespacings; } diff --git a/src/training/combine_lang_model.cpp b/src/training/combine_lang_model.cpp index 3f97238d..8ddfbd89 100644 --- a/src/training/combine_lang_model.cpp +++ b/src/training/combine_lang_model.cpp @@ -19,6 +19,7 @@ #include "commandlineflags.h" #include "commontraining.h" // CheckSharedLibraryVersion #include "lang_model_helpers.h" +#include "tesserrstream.h" // for tesserr #include "tprintf.h" #include "unicharset_training_utils.h" @@ -60,8 +61,8 @@ int main(int argc, char **argv) { tprintf("Failed to load unicharset from %s\n", FLAGS_input_unicharset.c_str()); return EXIT_FAILURE; } - tprintf("Loaded unicharset of size %zu from file %s\n", unicharset.size(), - FLAGS_input_unicharset.c_str()); + tesserr << "Loaded unicharset of size " << unicharset.size() + << " from file " << FLAGS_input_unicharset.c_str() << '\n'; // Set unichar properties tprintf("Setting unichar properties\n"); diff --git a/src/training/common/trainingsampleset.cpp b/src/training/common/trainingsampleset.cpp index 118febb6..bf1e40ce 100644 --- a/src/training/common/trainingsampleset.cpp +++ b/src/training/common/trainingsampleset.cpp @@ -28,6 +28,7 @@ #include "intfeaturemap.h" #include "intfeaturespace.h" #include "shapetable.h" +#include "tesserrstream.h" // for tesserr #include "trainingsample.h" #include "trainingsampleset.h" #include "unicity_table.h" @@ -566,8 +567,9 @@ void TrainingSampleSet::OrganizeByFontAndClass() { int font_id = samples_[s]->font_id(); int class_id = samples_[s]->class_id(); if (font_id < 0 || font_id >= font_id_map_.SparseSize()) { - tprintf("Font id = %d/%d, class id = %d/%d on sample %zu\n", font_id, - font_id_map_.SparseSize(), class_id, unicharset_size_, s); + tesserr << "Font id = " << font_id << '/' << font_id_map_.SparseSize() + << ", class id = " << class_id << '/' << unicharset_size_ + << " on sample " << s << '\n'; } ASSERT_HOST(font_id >= 0 && font_id < font_id_map_.SparseSize()); ASSERT_HOST(class_id >= 0 && class_id < unicharset_size_); diff --git a/src/training/pango/boxchar.cpp b/src/training/pango/boxchar.cpp index d31c5a8b..35c1a2b7 100644 --- a/src/training/pango/boxchar.cpp +++ b/src/training/pango/boxchar.cpp @@ -23,6 +23,7 @@ #include "fileio.h" #include "normstrngs.h" +#include "tesserrstream.h" // for tesserr #include "tprintf.h" #include "unicharset.h" #include "unicode/uchar.h" // from libicu @@ -100,7 +101,7 @@ void BoxChar::PrepareToWrite(std::vector *boxes) { InsertSpaces(rtl_rules, vertical_rules, boxes); for (size_t i = 0; i < boxes->size(); ++i) { if ((*boxes)[i]->box_ == nullptr) { - tprintf("Null box at index %zu\n", i); + tesserr << "Null box at index " << i << '\n'; } } if (rtl_rules) { diff --git a/src/training/unicharset/unicharset_training_utils.cpp b/src/training/unicharset/unicharset_training_utils.cpp index 853bee8e..a6e38a90 100644 --- a/src/training/unicharset/unicharset_training_utils.cpp +++ b/src/training/unicharset/unicharset_training_utils.cpp @@ -2,7 +2,6 @@ // File: unicharset_training_utils.cpp // Description: Training utilities for UNICHARSET. // Author: Ray Smith -// Created: Fri Oct 17 17:09:01 PDT 2014 // // (C) Copyright 2014, Google Inc. // Licensed under the Apache License, Version 2.0 (the "License"); @@ -29,6 +28,7 @@ #include "icuerrorcode.h" #include "normstrngs.h" #include "statistc.h" +#include "tesserrstream.h" // for tesserr #include "unicharset.h" #include "unicode/uchar.h" // from libicu #include "unicode/uscript.h" // from libicu @@ -189,8 +189,8 @@ void SetPropertiesForInputFile(const std::string &script_dir, // Load the input unicharset unicharset.load_from_file(input_unicharset_file.c_str()); - tprintf("Loaded unicharset of size %zu from file %s\n", unicharset.size(), - input_unicharset_file.c_str()); + tesserr << "Loaded unicharset of size " << unicharset.size() + << " from file " << input_unicharset_file << '\n'; // Set unichar properties tprintf("Setting unichar properties\n");