Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace some tprintf by tesserr stream (fixes Windows compiler warnings) #4345

Merged
merged 1 commit into from
Nov 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions src/ccmain/applybox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include <tesseract/unichar.h>
#include "pageres.h"
#include "tesseractclass.h"
#include "tesserrstream.h" // for tesserr
#include "unicharset.h"

#ifndef DISABLED_LEGACY_ENGINE
Expand Down Expand Up @@ -652,9 +653,10 @@ void Tesseract::SearchForText(const std::vector<BLOB_CHOICE_LIST *> *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;
Expand Down
12 changes: 6 additions & 6 deletions src/ccmain/paragraphs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -74,8 +75,8 @@ static bool AcceptableRowArgs(int debug_level, int min_num_rows, const char *fun
const std::vector<RowScratchRegisters> *rows, int row_start,
int row_end) {
if (row_start < 0 || static_cast<size_t>(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) {
Expand Down Expand Up @@ -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;
}
Expand Down
18 changes: 11 additions & 7 deletions src/ccstruct/detlinefit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 <algorithm>
#include <cfloat> // for FLT_MAX
Expand Down Expand Up @@ -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;
Expand Down
8 changes: 5 additions & 3 deletions src/ccstruct/imagedata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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();
Expand Down
9 changes: 5 additions & 4 deletions src/classify/shapetable.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include "fontinfo.h"
#include "genericheap.h"
#include "intmatcher.h"
#include "tesserrstream.h" // for tesserr

namespace tesseract {

Expand All @@ -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<double>(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
Expand Down
9 changes: 5 additions & 4 deletions src/dict/dict.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

#include "dict.h"

#include "tesserrstream.h" // for tesserr
#include "tprintf.h"

#include <cstdio>
Expand Down Expand Up @@ -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.
Expand Down
4 changes: 3 additions & 1 deletion src/lstm/series.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include "fullyconnected.h"
#include "networkscratch.h"
#include "scrollview.h"
#include "tesserrstream.h" // for tesserr
#include "tprintf.h"

namespace tesseract {
Expand Down Expand Up @@ -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");
Expand Down
8 changes: 5 additions & 3 deletions src/textord/baselinedetect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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;
}
Expand Down
5 changes: 3 additions & 2 deletions src/training/combine_lang_model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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");
Expand Down
6 changes: 4 additions & 2 deletions src/training/common/trainingsampleset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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_);
Expand Down
3 changes: 2 additions & 1 deletion src/training/pango/boxchar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -100,7 +101,7 @@ void BoxChar::PrepareToWrite(std::vector<BoxChar *> *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) {
Expand Down
6 changes: 3 additions & 3 deletions src/training/unicharset/unicharset_training_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -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
Expand Down Expand Up @@ -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");
Expand Down
Loading