Fix compiler warnings [-Wunused-but-set-variable]

- Use conditional compilation for variables which might be useful for debugging.
- Remove all other unused variables.

Signed-off-by: Stefan Weil <sw@weilnetz.de>
This commit is contained in:
Stefan Weil 2024-05-19 18:10:38 +02:00
parent 1644205d9e
commit d0b3d0915e
7 changed files with 18 additions and 11 deletions

View File

@ -1402,7 +1402,9 @@ char *TessBaseAPI::GetTSVText(int page_number) {
return nullptr;
}
#if !defined(NDEBUG)
int lcnt = 1, bcnt = 1, pcnt = 1, wcnt = 1;
#endif
int page_id = page_number + 1; // we use 1-based page numbers.
int page_num = page_id;
@ -1484,6 +1486,7 @@ char *TessBaseAPI::GetTSVText(int page_number) {
tsv_str += "\t" + std::to_string(res_it->Confidence(RIL_WORD));
tsv_str += "\t";
#if !defined(NDEBUG)
// Increment counts if at end of block/paragraph/textline.
if (res_it->IsAtFinalElement(RIL_TEXTLINE, RIL_WORD)) {
lcnt++;
@ -1494,13 +1497,16 @@ char *TessBaseAPI::GetTSVText(int page_number) {
if (res_it->IsAtFinalElement(RIL_BLOCK, RIL_WORD)) {
bcnt++;
}
#endif
do {
tsv_str += std::unique_ptr<const char[]>(res_it->GetUTF8Text(RIL_SYMBOL)).get();
res_it->Next(RIL_SYMBOL);
} while (!res_it->Empty(RIL_BLOCK) && !res_it->IsAtBeginningOf(RIL_WORD));
tsv_str += "\n"; // end of row
#if !defined(NDEBUG)
wcnt++;
#endif
}
char *ret = new char[tsv_str.length() + 1];

View File

@ -223,7 +223,9 @@ int orientation_and_script_detection(const char *filename, OSResults *osr,
// Returns a non-zero number of blobs if the page was successfully processed, or
// zero if the page had too few characters to be reliable
int os_detect(TO_BLOCK_LIST *port_blocks, OSResults *osr, tesseract::Tesseract *tess) {
#if !defined(NDEBUG)
int blobs_total = 0;
#endif
TO_BLOCK_IT block_it;
block_it.set_to_list(port_blocks);
@ -241,7 +243,9 @@ int os_detect(TO_BLOCK_LIST *port_blocks, OSResults *osr, tesseract::Tesseract *
BLOBNBOX *bbox = bbox_it.data();
C_BLOB *blob = bbox->cblob();
TBOX box = blob->bounding_box();
#if !defined(NDEBUG)
++blobs_total;
#endif
// Catch illegal value of box width and avoid division by zero.
if (box.width() == 0) {

View File

@ -112,7 +112,6 @@ float Classify::ComputeNormMatch(CLASS_ID ClassId, const FEATURE_STRUCT &feature
tprintf("\nChar norm for class %s\n", unicharset.id_to_unichar(ClassId));
}
int ProtoId = 0;
iterate(Protos) {
auto Proto = reinterpret_cast<PROTOTYPE *>(Protos->first_node());
float Delta = feature.Params[CharNormY] - Proto->Mean[CharNormY];
@ -145,8 +144,6 @@ float Classify::ComputeNormMatch(CLASS_ID ClassId, const FEATURE_STRUCT &feature
if (Match < BestMatch) {
BestMatch = Match;
}
ProtoId++;
}
return 1.0 - NormEvidenceOf(BestMatch);
} /* ComputeNormMatch */

View File

@ -151,7 +151,6 @@ void fix_row_pitch(TO_ROW *bad_row, // row to fix
int like_votes; // votes over page
int other_votes; // votes of unlike blocks
int block_index; // number of block
int row_index; // number of row
int maxwidth; // max pitch
TO_BLOCK_IT block_it = blocks; // block iterator
TO_BLOCK *block; // current block
@ -172,7 +171,6 @@ void fix_row_pitch(TO_ROW *bad_row, // row to fix
if (pb != nullptr && !pb->IsText()) {
continue; // Non text doesn't exist!
}
row_index = 1;
TO_ROW_IT row_it(block->get_rows());
for (row_it.mark_cycle_pt(); !row_it.cycled_list(); row_it.forward()) {
row = row_it.data();
@ -226,7 +224,6 @@ void fix_row_pitch(TO_ROW *bad_row, // row to fix
other_votes--;
}
}
row_index++;
}
block_index++;
}
@ -518,7 +515,6 @@ bool try_rows_fixed( // find line stats
bool testing_on // correct orientation
) {
TO_ROW *row; // current row
int32_t row_index; // row number.
int32_t def_fixed = 0; // counters
int32_t def_prop = 0;
int32_t maybe_fixed = 0;
@ -529,7 +525,6 @@ bool try_rows_fixed( // find line stats
float lower, upper; // cluster thresholds
TO_ROW_IT row_it = block->get_rows();
row_index = 1;
for (row_it.mark_cycle_pt(); !row_it.cycled_list(); row_it.forward()) {
row = row_it.data();
ASSERT_HOST(row->xheight > 0);
@ -541,7 +536,6 @@ bool try_rows_fixed( // find line stats
row->kern_size = lower;
}
}
row_index++;
}
count_block_votes(block, def_fixed, def_prop, maybe_fixed, maybe_prop, corr_fixed, corr_prop,
dunno);

View File

@ -116,7 +116,9 @@ int main(int argc, char *argv[]) {
InitFeatureDefs(&FeatureDefs);
ParseArguments(&argc, &argv);
#if !defined(NDEBUG)
int num_fonts = 0;
#endif
for (const char *PageName = *++argv; PageName != nullptr; PageName = *++argv) {
printf("Reading %s ...\n", PageName);
FILE *TrainingPage = fopen(PageName, "rb");
@ -124,7 +126,9 @@ int main(int argc, char *argv[]) {
if (TrainingPage) {
ReadTrainingSamples(FeatureDefs, PROGRAM_FEATURE_TYPE, 100, nullptr, TrainingPage, &CharList);
fclose(TrainingPage);
#if !defined(NDEBUG)
++num_fonts;
#endif
}
}
printf("Clustering ...\n");

View File

@ -114,7 +114,9 @@ void ErrorCounter::DebugNewErrors(ShapeClassifier *new_classifier, ShapeClassifi
ErrorCounter new_counter(new_classifier->GetUnicharset(), fontsize);
std::vector<UnicharRating> results;
#if !defined(NDEBUG)
int total_samples = 0;
#endif
int error_samples = 25;
int total_new_errors = 0;
// Iterate over all the samples, accumulating errors.
@ -145,7 +147,9 @@ void ErrorCounter::DebugNewErrors(ShapeClassifier *new_classifier, ShapeClassifi
}
}
}
#if !defined(NDEBUG)
++total_samples;
#endif
}
tprintf("Total new errors = %d\n", total_new_errors);
}

View File

@ -240,11 +240,9 @@ int SampleIterator::UniformSamples() {
// to 1. Returns the minimum assigned sample weight.
double SampleIterator::NormalizeSamples() {
double total_weight = 0.0;
int sample_count = 0;
for (Begin(); !AtEnd(); Next()) {
const TrainingSample &sample = GetSample();
total_weight += sample.weight();
++sample_count;
}
// Normalize samples.
double min_assigned_sample_weight = 1.0;