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

Fix some compiler warnings #4245

Merged
merged 5 commits into from
May 20, 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
6 changes: 6 additions & 0 deletions src/api/baseapi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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++;
Expand All @@ -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];
Expand Down
6 changes: 3 additions & 3 deletions src/api/pagerenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ Pta *SortBaseline(Pta *baseline_pts,
Pta *sorted_baseline_pts;

sorted_baseline_pts =
ptaSort(baseline_pts, L_SORT_BY_X, L_SORT_INCREASING, NULL);
ptaSort(baseline_pts, L_SORT_BY_X, L_SORT_INCREASING, nullptr);

do {
ptaGetPt(sorted_baseline_pts, index, &x0, &y0);
Expand Down Expand Up @@ -557,8 +557,8 @@ Pta *FitBaselineIntoLinePolygon(Pta *bottom_pts, Pta *baseline_pts,

// Calculate quartiles to find outliers
numaGetMedian(poly_bl_delta, &delta_median);
numaGetRankValue(poly_bl_delta, 0.25, NULL, 0, &delta_median_Q1);
numaGetRankValue(poly_bl_delta, 0.75, NULL, 0, &delta_median_Q3);
numaGetRankValue(poly_bl_delta, 0.25, nullptr, 0, &delta_median_Q1);
numaGetRankValue(poly_bl_delta, 0.75, nullptr, 0, &delta_median_Q3);

// Fit baseline into the polygon
// Todo: Needs maybe some adjustments to suppress fitting to superscript
Expand Down
4 changes: 4 additions & 0 deletions src/ccmain/osdetect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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) {
Expand Down
4 changes: 2 additions & 2 deletions src/ccstruct/points.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ class ICOORD {

/// find sq length
float sqlength() const {
return (float)(xcoord * xcoord + ycoord * ycoord);
return static_cast<float>(xcoord * xcoord + ycoord * ycoord);
}

/// find length
Expand All @@ -101,7 +101,7 @@ class ICOORD {

/// find angle
float angle() const {
return (float)std::atan2(ycoord, xcoord);
return std::atan2(static_cast<float>(ycoord), static_cast<float>(xcoord));
}

/// test equality
Expand Down
17 changes: 7 additions & 10 deletions src/classify/normmatch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,17 +52,17 @@ struct NORM_PROTOS {
* normalization adjustment. The equation that represents the transform is:
* 1 / (1 + (NormAdj / midpoint) ^ curl)
*/
static double NormEvidenceOf(double NormAdj) {
NormAdj /= classify_norm_adj_midpoint;
static float NormEvidenceOf(float NormAdj) {
NormAdj /= static_cast<float>(classify_norm_adj_midpoint);

if (classify_norm_adj_curl == 3) {
NormAdj = NormAdj * NormAdj * NormAdj;
} else if (classify_norm_adj_curl == 2) {
NormAdj = NormAdj * NormAdj;
} else {
NormAdj = pow(NormAdj, classify_norm_adj_curl);
NormAdj = std::pow(NormAdj, static_cast<float>(classify_norm_adj_curl));
}
return (1.0 / (1.0 + NormAdj));
return (1 / (1 + NormAdj));
}

/*----------------------------------------------------------------------------
Expand All @@ -73,7 +73,7 @@ static double NormEvidenceOf(double NormAdj) {
double_VAR(classify_norm_adj_midpoint, 32.0, "Norm adjust midpoint ...");
double_VAR(classify_norm_adj_curl, 2.0, "Norm adjust curl ...");
/** Weight of width variance against height and vertical position. */
const double kWidthErrorWeighting = 0.125;
const float kWidthErrorWeighting = 0.125f;

/*----------------------------------------------------------------------------
Public Code
Expand Down Expand Up @@ -102,7 +102,7 @@ float Classify::ComputeNormMatch(CLASS_ID ClassId, const FEATURE_STRUCT &feature
float Match = (feature.Params[CharNormLength] * feature.Params[CharNormLength] * 500.0f +
feature.Params[CharNormRx] * feature.Params[CharNormRx] * 8000.0f +
feature.Params[CharNormRy] * feature.Params[CharNormRy] * 8000.0f);
return (1.0f - NormEvidenceOf(Match));
return (1 - NormEvidenceOf(Match));
}

float BestMatch = FLT_MAX;
Expand All @@ -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];
Expand Down Expand Up @@ -145,10 +144,8 @@ float Classify::ComputeNormMatch(CLASS_ID ClassId, const FEATURE_STRUCT &feature
if (Match < BestMatch) {
BestMatch = Match;
}

ProtoId++;
}
return 1.0 - NormEvidenceOf(BestMatch);
return 1 - NormEvidenceOf(BestMatch);
} /* ComputeNormMatch */

void Classify::FreeNormProtos() {
Expand Down
16 changes: 8 additions & 8 deletions src/dict/dawg.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@

#ifndef __GNUC__
# ifdef _WIN32
# define NO_EDGE (int64_t)0xffffffffffffffffi64
# define NO_EDGE static_cast<int64_t>(0xffffffffffffffffi64)
# endif /*_WIN32*/
#else
# define NO_EDGE (int64_t)0xffffffffffffffffll
# define NO_EDGE static_cast<int64_t>(0xffffffffffffffffll)
#endif /*__GNUC__*/

namespace tesseract {
Expand Down Expand Up @@ -74,12 +74,12 @@ enum DawgType {
C o n s t a n t s
----------------------------------------------------------------------*/

#define FORWARD_EDGE (int32_t)0
#define BACKWARD_EDGE (int32_t)1
#define MAX_NODE_EDGES_DISPLAY (int64_t)100
#define MARKER_FLAG (int64_t)1
#define DIRECTION_FLAG (int64_t)2
#define WERD_END_FLAG (int64_t)4
#define FORWARD_EDGE static_cast<int32_t>(0)
#define BACKWARD_EDGE static_cast<int32_t>(1)
#define MAX_NODE_EDGES_DISPLAY static_cast<int64_t>(100)
#define MARKER_FLAG static_cast<int64_t>(1)
#define DIRECTION_FLAG static_cast<int64_t>(2)
#define WERD_END_FLAG static_cast<int64_t>(4)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible to replace with inline vars? constexpr inlines?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I think so (it the compiler produces the same efficient code). We could consider such a change for more macros in the future.

#define LETTER_START_BIT 0
#define NUM_FLAG_BITS 3
#define REFFORMAT "%" PRId64
Expand Down
6 changes: 0 additions & 6 deletions src/textord/topitch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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();
Expand Down Expand Up @@ -226,7 +224,6 @@ void fix_row_pitch(TO_ROW *bad_row, // row to fix
other_votes--;
}
}
row_index++;
}
block_index++;
}
Expand Down Expand Up @@ -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;
Expand All @@ -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);
Expand All @@ -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);
Expand Down
4 changes: 4 additions & 0 deletions src/training/cntraining.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,15 +116,19 @@ 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");
ASSERT_HOST(TrainingPage);
if (TrainingPage) {
ReadTrainingSamples(FeatureDefs, PROGRAM_FEATURE_TYPE, 100, nullptr, TrainingPage, &CharList);
fclose(TrainingPage);
#if !defined(NDEBUG)
++num_fonts;
#endif
}
}
printf("Clustering ...\n");
Expand Down
4 changes: 4 additions & 0 deletions src/training/common/errorcounter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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);
}
Expand Down
1 change: 0 additions & 1 deletion src/training/common/networkbuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,6 @@ Network *NetworkBuilder::BuildFromString(const StaticShape &input_shape, const c
return ParseOutput(input_shape, str);
default:
tprintf("Invalid network spec:%s\n", *str);
return nullptr;
}
return nullptr;
}
Expand Down
2 changes: 0 additions & 2 deletions src/training/common/sampleiterator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/wordrec/chopper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ SEAM *Wordrec::improve_one_blob(const std::vector<BLOB_CHOICE *> &blob_choices,
// TODO(rays) it may eventually help to allow italic_blob to be true,
seam = chop_numbered_blob(word->chopped_word, *blob_number, italic_blob, word->seam_array);
if (seam != nullptr) {
return seam; // Success!
break; // Success!
}
if (blob_choices[*blob_number] == nullptr) {
return nullptr;
Expand Down
1 change: 0 additions & 1 deletion unittest/applybox_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ class ApplyBoxTest : public testing::Test {
if (!SetImage(imagefile)) {
// eng.traineddata not found or other problem during Init.
GTEST_SKIP();
return;
}
if (line_mode) {
api_.SetVariable("tessedit_resegment_from_line_boxes", "1");
Expand Down
5 changes: 0 additions & 5 deletions unittest/baseapi_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,6 @@ TEST_F(TesseractTest, HOCRWorksWithoutSetInputName) {
if (api.Init(TessdataPath().c_str(), "eng", tesseract::OEM_TESSERACT_ONLY) == -1) {
// eng.traineddata not found.
GTEST_SKIP();
return;
}
Image src_pix = pixRead(TestDataNameToPath("HelloGoogle.tif").c_str());
CHECK(src_pix);
Expand All @@ -143,7 +142,6 @@ TEST_F(TesseractTest, HOCRContainsBaseline) {
if (api.Init(TessdataPath().c_str(), "eng", tesseract::OEM_TESSERACT_ONLY) == -1) {
// eng.traineddata not found.
GTEST_SKIP();
return;
}
Image src_pix = pixRead(TestDataNameToPath("HelloGoogle.tif").c_str());
CHECK(src_pix);
Expand Down Expand Up @@ -179,7 +177,6 @@ TEST_F(TesseractTest, AdaptToWordStrTest) {
if (api.Init(TessdataPath().c_str(), "eng", tesseract::OEM_TESSERACT_ONLY) == -1) {
// eng.traineddata not found.
GTEST_SKIP();
return;
}
api.SetVariable("matcher_sufficient_examples_for_prototyping", "1");
api.SetVariable("classify_class_pruner_threshold", "220");
Expand Down Expand Up @@ -215,7 +212,6 @@ TEST_F(TesseractTest, BasicLSTMTest) {
if (api.Init(TessdataPath().c_str(), "eng", tesseract::OEM_LSTM_ONLY) == -1) {
// eng.traineddata not found.
GTEST_SKIP();
return;
}
Image src_pix = pixRead(TestDataNameToPath("phototest_2.tif").c_str());
CHECK(src_pix);
Expand All @@ -239,7 +235,6 @@ TEST_F(TesseractTest, LSTMGeometryTest) {
if (api.Init(TessdataPath().c_str(), "eng", tesseract::OEM_LSTM_ONLY) == -1) {
// eng.traineddata not found.
GTEST_SKIP();
return;
}
api.SetImage(src_pix);
ASSERT_EQ(api.Recognize(nullptr), 0);
Expand Down
Loading