22 #include "allheaders.h"
30 int scale,
int scaled_yres,
int rect_left,
31 int rect_top,
int rect_width,
34 rect_width, rect_height),
35 line_separator_(
"\n"),
36 paragraph_separator_(
"\n") {}
78 int length = text.
length() + 1;
79 char* result =
new char[length];
80 strncpy(result, text.
c_str(), length);
99 float mean_certainty = 0.0f;
100 int certainty_count = 0;
109 mean_certainty += best_choice->
certainty();
118 mean_certainty += best_choice->
certainty();
128 mean_certainty += best_choice->
certainty();
134 mean_certainty += best_choice->
certainty();
141 if (certainty_count > 0) {
142 mean_certainty /= certainty_count;
143 return ClipToRange(100 + 5 * mean_certainty, 0.0f, 100.0f);
149 float* ascenders)
const {
165 bool* is_bold,
bool* is_italic,
bool* is_underlined,
bool* is_monospace,
166 bool* is_serif,
bool* is_smallcaps,
int* pointsize,
int* font_id)
const {
167 const char* result =
nullptr;
182 #ifndef DISABLED_LEGACY_ENGINE
187 *is_bold = font_info->
is_bold();
189 *is_underlined =
false;
192 result = font_info->
name;
194 #endif // ndef DISABLED_LEGACY_ENGINE
202 *is_underlined =
false;
203 *is_monospace =
false;
205 *is_smallcaps =
false;
225 if (has_rtl && !has_ltr)
227 if (has_ltr && !has_rtl)
229 if (!has_ltr && !has_rtl)
264 #ifndef DISABLED_LEGACY_ENGINE
272 #endif // ndef DISABLED_LEGACY_ENGINE
313 int length = truth_text.
length() + 1;
314 char* result =
new char[length];
315 strncpy(result, truth_text.
c_str(), length);
328 for (
int i = 0; i < best_choice->
length(); ++i) {
331 int length = ocr_text.
length() + 1;
332 char* result =
new char[length];
333 strncpy(result, ocr_text.
c_str(), length);
378 word_res_ = result_it.
it_->
word();
379 oemLSTM_ = word_res_->tesseract->AnyLSTMLang();
381 bool oemLegacy = word_res_->tesseract->AnyTessLang();
383 bool lstm_choice_mode = word_res_->tesseract->lstm_choice_mode;
384 rating_coefficient_ = word_res_->tesseract->lstm_rating_coefficient;
386 BLOB_CHOICE_LIST* choices =
nullptr;
388 if (oemLSTM_ && !word_res_->CTC_symbol_choices.empty()) {
389 if (!word_res_->CTC_symbol_choices[0].empty() &&
390 strcmp(word_res_->CTC_symbol_choices[0][0].first,
" ")) {
391 blanks_before_word_ = 0;
393 auto index = *tstep_index_;
394 index += blanks_before_word_;
395 if (index < word_res_->CTC_symbol_choices.size()) {
396 LSTM_choices_ = &word_res_->CTC_symbol_choices[index];
400 if ((oemLegacy || !lstm_choice_mode) && word_res_->ratings !=
nullptr)
401 choices = word_res_->GetBlobChoices(result_it.
blob_index_);
402 if (choices !=
nullptr && !choices->empty()) {
403 choice_it_ =
new BLOB_CHOICE_IT(choices);
404 choice_it_->mark_cycle_pt();
406 choice_it_ =
nullptr;
408 if (LSTM_choices_ !=
nullptr && !LSTM_choices_->empty()) {
409 LSTM_choice_it_ = LSTM_choices_->begin();
419 if (oemLSTM_ && LSTM_choices_ !=
nullptr && !LSTM_choices_->empty()) {
420 if (LSTM_choice_it_ != LSTM_choices_->end() &&
421 next(LSTM_choice_it_) == LSTM_choices_->end()) {
428 if (choice_it_ ==
nullptr)
430 choice_it_->forward();
431 return !choice_it_->cycled_list();
438 if (oemLSTM_ && LSTM_choices_ !=
nullptr && !LSTM_choices_->empty()) {
439 std::pair<const char*, float> choice = *LSTM_choice_it_;
442 if (choice_it_ ==
nullptr)
444 UNICHAR_ID id = choice_it_->data()->unichar_id();
457 if (oemLSTM_ && LSTM_choices_ !=
nullptr && !LSTM_choices_->empty()) {
458 std::pair<const char*, float> choice = *LSTM_choice_it_;
459 confidence = 100 - rating_coefficient_ * choice.second;
461 if (choice_it_ ==
nullptr)
463 confidence = 100 + 5 * choice_it_->data()->certainty();
469 std::vector<std::vector<std::pair<const char*, float>>>*
471 int offset = *tstep_index_ + blanks_before_word_;
478 void ChoiceIterator::filterSpaces() {
479 if (LSTM_choices_->empty())
481 std::vector<std::pair<const char*, float>>::iterator it;
482 for (it = LSTM_choices_->begin(); it != LSTM_choices_->end();) {
483 if (!strcmp(it->first,
" ")) {
484 it = LSTM_choices_->erase(it);