ccmain: Fix some signed/unsigned compiler warnings

Signed-off-by: Stefan Weil <sw@weilnetz.de>
This commit is contained in:
Stefan Weil 2021-10-09 20:36:25 +02:00
parent a9c3f6d87f
commit 3a4828bcf4
3 changed files with 15 additions and 22 deletions

View File

@ -243,7 +243,7 @@ void Tesseract::MaximallyChopWord(const std::vector<TBOX> &boxes, BLOCK *block,
std::vector<BLOB_CHOICE *> blob_choices;
ASSERT_HOST(!word_res->chopped_word->blobs.empty());
auto rating = static_cast<float>(INT8_MAX);
for (int i = 0; i < word_res->chopped_word->NumBlobs(); ++i) {
for (unsigned i = 0; i < word_res->chopped_word->NumBlobs(); ++i) {
// The rating and certainty are not quite arbitrary. Since
// select_blob_to_chop uses the worst certainty to choose, they all have
// to be different, so starting with INT8_MAX, subtract 1/8 for each blob
@ -257,7 +257,7 @@ void Tesseract::MaximallyChopWord(const std::vector<TBOX> &boxes, BLOCK *block,
rating -= 0.125f;
}
const double e = exp(1.0); // The base of natural logs.
int blob_number;
unsigned blob_number;
int right_chop_index = 0;
if (!assume_fixed_pitch_char_segment) {
// We only chop if the language is not fixed pitch like CJK.
@ -613,8 +613,8 @@ bool Tesseract::FindSegmentation(const std::vector<UNICHAR_ID> &target_text, WER
/// @param best_rating
/// @param best_segmentation
void Tesseract::SearchForText(const std::vector<BLOB_CHOICE_LIST *> *choices, int choices_pos,
int choices_length, const std::vector<UNICHAR_ID> &target_text,
int text_index, float rating, std::vector<int> *segmentation,
unsigned choices_length, const std::vector<UNICHAR_ID> &target_text,
unsigned text_index, float rating, std::vector<int> *segmentation,
float *best_rating, std::vector<int> *best_segmentation) {
const UnicharAmbigsVector &table = getDict().getUnicharAmbigs().dang_ambigs();
for (unsigned length = 1; length <= choices[choices_pos].size(); ++length) {
@ -625,12 +625,12 @@ void Tesseract::SearchForText(const std::vector<BLOB_CHOICE_LIST *> *choices, in
for (choice_it.mark_cycle_pt(); !choice_it.cycled_list(); choice_it.forward()) {
const BLOB_CHOICE *choice = choice_it.data();
choice_rating = choice->rating();
UNICHAR_ID class_id = choice->unichar_id();
auto class_id = choice->unichar_id();
if (class_id == target_text[text_index]) {
break;
}
// Search ambigs table.
if (class_id < table.size() && table[class_id] != nullptr) {
if (static_cast<size_t>(class_id) < table.size() && table[class_id] != nullptr) {
AmbigSpec_IT spec_it(table[class_id]);
for (spec_it.mark_cycle_pt(); !spec_it.cycled_list(); spec_it.forward()) {
const AmbigSpec *ambig_spec = spec_it.data();

View File

@ -593,7 +593,7 @@ public:
void recog_word_recursive(WERD_RES *word);
void recog_word(WERD_RES *word);
void split_and_recog_word(WERD_RES *word);
void split_word(WERD_RES *word, int split_pt, WERD_RES **right_piece,
void split_word(WERD_RES *word, unsigned split_pt, WERD_RES **right_piece,
BlamerBundle **orig_blamer_bundle) const;
void join_words(WERD_RES *word, WERD_RES *word2, BlamerBundle *orig_bb) const;
//// fixspace.cpp ///////////////////////////////////////////////////////
@ -722,8 +722,8 @@ public:
// vector holding classification results for a sequence of consecutive
// blobs, with index 0 being a single blob, index 1 being 2 blobs etc.
void SearchForText(const std::vector<BLOB_CHOICE_LIST *> *choices, int choices_pos,
int choices_length, const std::vector<UNICHAR_ID> &target_text,
int text_index, float rating, std::vector<int> *segmentation,
unsigned choices_length, const std::vector<UNICHAR_ID> &target_text,
unsigned text_index, float rating, std::vector<int> *segmentation,
float *best_rating, std::vector<int> *best_segmentation);
// Counts up the labelled words and the blobs within.
// Deletes all unused or emptied words, counting the unused ones.

View File

@ -47,14 +47,7 @@ void Tesseract::recog_word(WERD_RES *word) {
ASSERT_HOST(!word->chopped_word->blobs.empty());
recog_word_recursive(word);
word->SetupBoxWord();
if (word->best_choice->length() != word->box_word->length()) {
tprintf(
"recog_word ASSERT FAIL String:\"%s\"; "
"Strlen=%d; #Blobs=%d\n",
word->best_choice->debug_string().c_str(), word->best_choice->length(),
word->box_word->length());
}
ASSERT_HOST(word->best_choice->length() == word->box_word->length());
ASSERT_HOST(static_cast<unsigned>(word->best_choice->length()) == word->box_word->length());
// Check that the ratings matrix size matches the sum of all the
// segmentation states.
if (!word->StatesAllValid()) {
@ -82,7 +75,7 @@ void Tesseract::recog_word(WERD_RES *word) {
// Factored out from control.cpp
ASSERT_HOST((word->best_choice == nullptr) == (word->raw_choice == nullptr));
if (word->best_choice == nullptr || word->best_choice->empty() ||
static_cast<int>(strspn(word->best_choice->unichar_string().c_str(), " ")) ==
strspn(word->best_choice->unichar_string().c_str(), " ") ==
word->best_choice->length()) {
word->tess_failed = true;
word->reject_map.initialise(word->box_word->length());
@ -99,7 +92,7 @@ void Tesseract::recog_word(WERD_RES *word) {
* Convert the output back to editor form.
**********************************************************************/
void Tesseract::recog_word_recursive(WERD_RES *word) {
int word_length = word->chopped_word->NumBlobs(); // no of blobs
auto word_length = word->chopped_word->NumBlobs(); // no of blobs
if (word_length > MAX_UNDIVIDED_LENGTH) {
return split_and_recog_word(word);
}
@ -134,7 +127,7 @@ void Tesseract::split_and_recog_word(WERD_RES *word) {
// Find the biggest blob gap in the chopped_word.
int bestgap = -INT32_MAX;
int split_index = 0;
for (int b = 1; b < word->chopped_word->NumBlobs(); ++b) {
for (unsigned b = 1; b < word->chopped_word->NumBlobs(); ++b) {
TBOX prev_box = word->chopped_word->blobs[b - 1]->bounding_box();
TBOX blob_box = word->chopped_word->blobs[b]->bounding_box();
int gap = blob_box.left() - prev_box.right();
@ -167,7 +160,7 @@ void Tesseract::split_and_recog_word(WERD_RES *word) {
* and will now be owned by the caller. New blamer bundles are forged for the
* two pieces.
**********************************************************************/
void Tesseract::split_word(WERD_RES *word, int split_pt, WERD_RES **right_piece,
void Tesseract::split_word(WERD_RES *word, unsigned split_pt, WERD_RES **right_piece,
BlamerBundle **orig_blamer_bundle) const {
ASSERT_HOST(split_pt > 0 && split_pt < word->chopped_word->NumBlobs());
@ -181,7 +174,7 @@ void Tesseract::split_word(WERD_RES *word, int split_pt, WERD_RES **right_piece,
TWERD *chopped = word->chopped_word;
auto *chopped2 = new TWERD;
chopped2->blobs.reserve(chopped->NumBlobs() - split_pt);
for (int i = split_pt; i < chopped->NumBlobs(); ++i) {
for (auto i = split_pt; i < chopped->NumBlobs(); ++i) {
chopped2->blobs.push_back(chopped->blobs[i]);
}
chopped->blobs.resize(split_pt);