#include <blamer.h>
|
| BlamerBundle () |
|
| BlamerBundle (const BlamerBundle &other) |
|
| ~BlamerBundle () |
|
STRING | TruthString () const |
|
IncorrectResultReason | incorrect_result_reason () const |
|
bool | NoTruth () const |
|
bool | HasDebugInfo () const |
|
const STRING & | debug () const |
|
const STRING & | misadaption_debug () const |
|
void | UpdateBestRating (float rating) |
|
int | correct_segmentation_length () const |
|
bool | MatrixPositionCorrect (int index, const MATRIX_COORD &coord) |
|
void | set_best_choice_is_dict_and_top_choice (bool value) |
|
const char * | lattice_data () const |
|
int | lattice_size () const |
|
void | set_lattice_data (const char *data, int size) |
|
const tesseract::ParamsTrainingBundle & | params_training_bundle () const |
|
void | AddHypothesis (const tesseract::ParamsTrainingHypothesis &hypo) |
|
void | SetWordTruth (const UNICHARSET &unicharset, const char *truth_str, const TBOX &word_box) |
|
void | SetSymbolTruth (const UNICHARSET &unicharset, const char *char_str, const TBOX &char_box) |
|
void | SetRejectedTruth () |
|
bool | ChoiceIsCorrect (const WERD_CHOICE *word_choice) const |
|
void | ClearResults () |
|
void | CopyTruth (const BlamerBundle &other) |
|
void | CopyResults (const BlamerBundle &other) |
|
const char * | IncorrectReason () const |
|
void | FillDebugString (const STRING &msg, const WERD_CHOICE *choice, STRING *debug) |
|
void | SetupNormTruthWord (const DENORM &denorm) |
|
void | SplitBundle (int word1_right, int word2_left, bool debug, BlamerBundle *bundle1, BlamerBundle *bundle2) const |
|
void | JoinBlames (const BlamerBundle &bundle1, const BlamerBundle &bundle2, bool debug) |
|
void | BlameClassifier (const UNICHARSET &unicharset, const TBOX &blob_box, const BLOB_CHOICE_LIST &choices, bool debug) |
|
void | SetChopperBlame (const WERD_RES *word, bool debug) |
|
void | BlameClassifierOrLangModel (const WERD_RES *word, const UNICHARSET &unicharset, bool valid_permuter, bool debug) |
|
void | SetupCorrectSegmentation (const TWERD *word, bool debug) |
|
bool | GuidedSegsearchNeeded (const WERD_CHOICE *best_choice) const |
|
void | InitForSegSearch (const WERD_CHOICE *best_choice, MATRIX *ratings, UNICHAR_ID wildcard_id, bool debug, STRING *debug_str, TessResultCallback2< bool, int, int > *pp_cb) |
|
bool | GuidedSegsearchStillGoing () const |
|
void | FinishSegSearch (const WERD_CHOICE *best_choice, bool debug, STRING *debug_str) |
|
void | SetMisAdaptionDebug (const WERD_CHOICE *best_choice, bool debug) |
|
Definition at line 102 of file blamer.h.
◆ BlamerBundle() [1/2]
BlamerBundle::BlamerBundle |
( |
| ) |
|
|
inline |
Definition at line 104 of file blamer.h.
104 : truth_has_char_boxes_(
false),
◆ BlamerBundle() [2/2]
◆ ~BlamerBundle()
BlamerBundle::~BlamerBundle |
( |
| ) |
|
|
inline |
Definition at line 111 of file blamer.h.
111 {
delete[] lattice_data_; }
◆ AddHypothesis()
◆ BlameClassifier()
void BlamerBundle::BlameClassifier |
( |
const UNICHARSET & |
unicharset, |
|
|
const TBOX & |
blob_box, |
|
|
const BLOB_CHOICE_LIST & |
choices, |
|
|
bool |
debug |
|
) |
| |
Definition at line 265 of file blamer.cpp.
269 if (!truth_has_char_boxes_ ||
273 for (
int b = 0; b < norm_truth_word_.
length(); ++b) {
274 const TBOX &truth_box = norm_truth_word_.
BlobBox(b);
280 bool incorrect_adapted =
false;
281 UNICHAR_ID incorrect_adapted_id = INVALID_UNICHAR_ID;
282 const char *truth_str = truth_text_[b].string();
285 BLOB_CHOICE_IT choices_it(
const_cast<BLOB_CHOICE_LIST*
>(&choices));
286 for (choices_it.mark_cycle_pt(); !choices_it.cycled_list();
287 choices_it.forward()) {
294 incorrect_adapted =
true;
299 STRING debug_str =
"unichar ";
300 debug_str += truth_str;
301 debug_str +=
" not found in classification list";
303 }
else if (incorrect_adapted) {
304 STRING debug_str =
"better rating for adapted ";
306 debug_str +=
" than for correct ";
307 debug_str += truth_str;
◆ BlameClassifierOrLangModel()
void BlamerBundle::BlameClassifierOrLangModel |
( |
const WERD_RES * |
word, |
|
|
const UNICHARSET & |
unicharset, |
|
|
bool |
valid_permuter, |
|
|
bool |
debug |
|
) |
| |
Definition at line 377 of file blamer.cpp.
380 if (valid_permuter) {
382 best_choice_is_dict_and_top_choice_ =
true;
387 for (blob_choice_it.mark_cycle_pt(); !blob_choice_it.cycled_list();
388 blob_choice_it.forward()) {
389 if (!(unicharset.
get_fragment(blob_choice_it.data()->unichar_id()))) {
390 first_choice = blob_choice_it.data();
396 best_choice_is_dict_and_top_choice_ =
false;
402 if (best_choice_is_dict_and_top_choice_) {
403 debug_str =
"Best choice is: incorrect, top choice, dictionary word";
404 debug_str +=
" with permuter ";
407 debug_str =
"Classifier/Old LM tradeoff is to blame";
◆ ChoiceIsCorrect()
bool BlamerBundle::ChoiceIsCorrect |
( |
const WERD_CHOICE * |
word_choice | ) |
const |
Definition at line 119 of file blamer.cpp.
120 if (word_choice ==
nullptr)
return false;
123 for (
int i = 0; i < word_choice->
length(); ++i) {
128 return truth_str == normed_choice_str;
◆ ClearResults()
void BlamerBundle::ClearResults |
( |
| ) |
|
|
inline |
Definition at line 189 of file blamer.h.
191 norm_box_tolerance_ = 0;
194 segsearch_is_looking_for_blame_ =
false;
196 correct_segmentation_cols_.
clear();
197 correct_segmentation_rows_.
clear();
198 best_choice_is_dict_and_top_choice_ =
false;
199 delete[] lattice_data_;
200 lattice_data_ =
nullptr;
◆ CopyResults()
void BlamerBundle::CopyResults |
( |
const BlamerBundle & |
other | ) |
|
|
inline |
Definition at line 210 of file blamer.h.
211 norm_truth_word_ = other.norm_truth_word_;
212 norm_box_tolerance_ = other.norm_box_tolerance_;
213 incorrect_result_reason_ = other.incorrect_result_reason_;
214 segsearch_is_looking_for_blame_ = other.segsearch_is_looking_for_blame_;
215 best_correctly_segmented_rating_ = other.best_correctly_segmented_rating_;
216 correct_segmentation_cols_ = other.correct_segmentation_cols_;
217 correct_segmentation_rows_ = other.correct_segmentation_rows_;
218 best_choice_is_dict_and_top_choice_ =
219 other.best_choice_is_dict_and_top_choice_;
220 if (other.lattice_data_ !=
nullptr) {
221 lattice_data_ =
new char[other.lattice_size_];
222 memcpy(lattice_data_, other.lattice_data_, other.lattice_size_);
223 lattice_size_ = other.lattice_size_;
225 lattice_data_ =
nullptr;
◆ CopyTruth()
Definition at line 203 of file blamer.h.
204 truth_has_char_boxes_ = other.truth_has_char_boxes_;
205 truth_word_ = other.truth_word_;
206 truth_text_ = other.truth_text_;
207 incorrect_result_reason_ =
◆ correct_segmentation_length()
int BlamerBundle::correct_segmentation_length |
( |
| ) |
const |
|
inline |
Definition at line 140 of file blamer.h.
141 return correct_segmentation_cols_.
length();
◆ debug()
const STRING& BlamerBundle::debug |
( |
| ) |
const |
|
inline |
◆ FillDebugString()
Definition at line 131 of file blamer.cpp.
134 (*debug) +=
"Truth ";
135 for (
int i = 0; i < this->truth_text_.
length(); ++i) {
136 (*debug) += this->truth_text_[i];
138 if (!this->truth_has_char_boxes_) (*debug) +=
" (no char boxes)";
139 if (choice !=
nullptr) {
140 (*debug) +=
" Choice ";
143 (*debug) += choice_str;
◆ FinishSegSearch()
void BlamerBundle::FinishSegSearch |
( |
const WERD_CHOICE * |
best_choice, |
|
|
bool |
debug, |
|
|
STRING * |
debug_str |
|
) |
| |
Definition at line 519 of file blamer.cpp.
532 if (segsearch_is_looking_for_blame_) {
533 segsearch_is_looking_for_blame_ =
false;
534 if (best_choice_is_dict_and_top_choice_) {
535 *debug_str =
"Best choice is: incorrect, top choice, dictionary word";
536 *debug_str +=
" with permuter ";
539 }
else if (best_correctly_segmented_rating_ <
541 *debug_str +=
"Correct segmentation state was not explored";
544 if (best_correctly_segmented_rating_ >=
546 *debug_str +=
"Correct segmentation paths were pruned by LM\n";
549 best_correctly_segmented_rating_);
◆ GuidedSegsearchNeeded()
bool BlamerBundle::GuidedSegsearchNeeded |
( |
const WERD_CHOICE * |
best_choice | ) |
const |
Definition at line 471 of file blamer.cpp.
473 !segsearch_is_looking_for_blame_ &&
474 truth_has_char_boxes_ &&
◆ GuidedSegsearchStillGoing()
bool BlamerBundle::GuidedSegsearchStillGoing |
( |
| ) |
const |
Definition at line 514 of file blamer.cpp.
515 return segsearch_is_looking_for_blame_;
◆ HasDebugInfo()
bool BlamerBundle::HasDebugInfo |
( |
| ) |
const |
|
inline |
◆ incorrect_result_reason()
Definition at line 120 of file blamer.h.
121 return incorrect_result_reason_;
◆ IncorrectReason()
const char * BlamerBundle::IncorrectReason |
( |
| ) |
const |
◆ IncorrectReasonName()
◆ InitForSegSearch()
Definition at line 484 of file blamer.cpp.
488 segsearch_is_looking_for_blame_ =
true;
490 tprintf(
"segsearch starting to look for blame\n");
494 *debug_str +=
"Correct segmentation:\n";
495 for (
int idx = 0; idx < correct_segmentation_cols_.
length(); ++idx) {
496 debug_str->
add_str_int(
"col=", correct_segmentation_cols_[idx]);
497 debug_str->
add_str_int(
" row=", correct_segmentation_rows_[idx]);
499 if (!ratings->
Classified(correct_segmentation_cols_[idx],
500 correct_segmentation_rows_[idx],
502 !cb->Run(correct_segmentation_cols_[idx],
503 correct_segmentation_rows_[idx])) {
504 segsearch_is_looking_for_blame_ =
false;
505 *debug_str +=
"\nFailed to insert pain point\n";
◆ JoinBlames()
Definition at line 233 of file blamer.cpp.
238 if (bundle1.incorrect_result_reason_ !=
IRR_CORRECT &&
241 debug_str +=
"Blame from part 1: ";
242 debug_str += bundle1.debug_;
243 irr = bundle1.incorrect_result_reason_;
245 if (bundle2.incorrect_result_reason_ !=
IRR_CORRECT &&
248 debug_str +=
"Blame from part 2: ";
249 debug_str += bundle2.debug_;
251 irr = bundle2.incorrect_result_reason_;
252 }
else if (irr != bundle2.incorrect_result_reason_) {
256 incorrect_result_reason_ = irr;
258 SetBlame(irr, debug_str,
nullptr,
debug);
◆ LastChanceBlame()
void BlamerBundle::LastChanceBlame |
( |
bool |
debug, |
|
|
WERD_RES * |
word |
|
) |
| |
|
static |
Definition at line 560 of file blamer.cpp.
572 STRING debug_str =
"Choice is incorrect after recognition";
◆ lattice_data()
const char* BlamerBundle::lattice_data |
( |
| ) |
const |
|
inline |
Definition at line 152 of file blamer.h.
153 return lattice_data_;
◆ lattice_size()
int BlamerBundle::lattice_size |
( |
| ) |
const |
|
inline |
Definition at line 155 of file blamer.h.
156 return lattice_size_;
◆ MatrixPositionCorrect()
bool BlamerBundle::MatrixPositionCorrect |
( |
int |
index, |
|
|
const MATRIX_COORD & |
coord |
|
) |
| |
|
inline |
Definition at line 145 of file blamer.h.
146 return correct_segmentation_cols_[index] == coord.
col &&
147 correct_segmentation_rows_[index] == coord.
row;
◆ misadaption_debug()
const STRING& BlamerBundle::misadaption_debug |
( |
| ) |
const |
|
inline |
Definition at line 133 of file blamer.h.
134 return misadaption_debug_;
◆ NoTruth()
bool BlamerBundle::NoTruth |
( |
| ) |
const |
|
inline |
◆ params_training_bundle()
Definition at line 165 of file blamer.h.
166 return params_training_bundle_;
◆ set_best_choice_is_dict_and_top_choice()
void BlamerBundle::set_best_choice_is_dict_and_top_choice |
( |
bool |
value | ) |
|
|
inline |
Definition at line 149 of file blamer.h.
150 best_choice_is_dict_and_top_choice_ = value;
◆ set_lattice_data()
void BlamerBundle::set_lattice_data |
( |
const char * |
data, |
|
|
int |
size |
|
) |
| |
|
inline |
Definition at line 158 of file blamer.h.
159 lattice_size_ = size;
160 delete [] lattice_data_;
161 lattice_data_ =
new char[lattice_size_];
162 memcpy(lattice_data_, data, lattice_size_);
◆ SetChopperBlame()
void BlamerBundle::SetChopperBlame |
( |
const WERD_RES * |
word, |
|
|
bool |
debug |
|
) |
| |
Definition at line 318 of file blamer.cpp.
319 if (
NoTruth() || !truth_has_char_boxes_ ||
324 bool missing_chop =
false;
328 int16_t truth_x = -1;
329 while (box_index < truth_word_.
length() && blob_index < num_blobs) {
336 truth_x + norm_box_tolerance_) {
343 if (missing_chop || box_index < norm_truth_word_.
length()) {
346 debug_str.
add_str_int(
"Detected missing chop (tolerance=",
347 norm_box_tolerance_);
348 debug_str +=
") at Bounding Box=";
351 debug_str.
add_str_int(
"\nNo chop for truth at x=", truth_x);
354 norm_truth_word_.
length() - box_index);
355 debug_str +=
" truth box(es)";
357 debug_str +=
"\nMaximally chopped word boxes:\n";
358 for (blob_index = 0; blob_index < num_blobs; ++blob_index) {
363 debug_str +=
"Truth bounding boxes:\n";
364 for (box_index = 0; box_index < norm_truth_word_.
length(); ++box_index) {
◆ SetMisAdaptionDebug()
void BlamerBundle::SetMisAdaptionDebug |
( |
const WERD_CHOICE * |
best_choice, |
|
|
bool |
debug |
|
) |
| |
Definition at line 587 of file blamer.cpp.
591 misadaption_debug_ =
"misadapt to word (";
593 misadaption_debug_ +=
"): ";
◆ SetRejectedTruth()
void BlamerBundle::SetRejectedTruth |
( |
| ) |
|
Definition at line 113 of file blamer.cpp.
115 truth_has_char_boxes_ =
false;
◆ SetSymbolTruth()
void BlamerBundle::SetSymbolTruth |
( |
const UNICHARSET & |
unicharset, |
|
|
const char * |
char_str, |
|
|
const TBOX & |
char_box |
|
) |
| |
Definition at line 94 of file blamer.cpp.
96 STRING symbol_str(char_str);
98 if (
id != INVALID_UNICHAR_ID) {
100 if (normed_uch.length() > 0) symbol_str = normed_uch;
102 int length = truth_word_.
length();
106 truth_has_char_boxes_ =
true;
107 else if (truth_word_.
BlobBox(length - 1) == char_box)
108 truth_has_char_boxes_ =
false;
◆ SetupCorrectSegmentation()
void BlamerBundle::SetupCorrectSegmentation |
( |
const TWERD * |
word, |
|
|
bool |
debug |
|
) |
| |
Definition at line 415 of file blamer.cpp.
416 #ifndef DISABLED_LEGACY_ENGINE
418 #endif // ndef DISABLED_LEGACY_ENGINE
419 if (incorrect_result_reason_ !=
IRR_CORRECT || !truth_has_char_boxes_)
423 debug_str +=
"Blamer computing correct_segmentation_cols\n";
424 int curr_box_col = 0;
425 int next_box_col = 0;
427 if (num_blobs == 0)
return;
429 int16_t next_box_x = word->
blobs[blob_index]->bounding_box().right();
430 for (
int truth_idx = 0; blob_index < num_blobs &&
431 truth_idx < norm_truth_word_.
length();
434 int16_t curr_box_x = next_box_x;
435 if (blob_index + 1 < num_blobs)
436 next_box_x = word->
blobs[blob_index + 1]->bounding_box().right();
437 int16_t truth_x = norm_truth_word_.
BlobBox(truth_idx).
right();
438 debug_str.
add_str_int(
"Box x coord vs. truth: ", curr_box_x);
441 if (curr_box_x > (truth_x + norm_box_tolerance_)) {
443 }
else if (curr_box_x >= truth_x - norm_box_tolerance_ &&
444 (blob_index + 1 >= num_blobs ||
445 next_box_x > truth_x + norm_box_tolerance_)) {
446 correct_segmentation_cols_.
push_back(curr_box_col);
447 correct_segmentation_rows_.
push_back(next_box_col-1);
452 curr_box_col = next_box_col;
455 if (blob_index < num_blobs ||
456 correct_segmentation_cols_.
length() != norm_truth_word_.
length()) {
457 debug_str.
add_str_int(
"Blamer failed to find correct segmentation"
458 " (tolerance=", norm_box_tolerance_);
459 if (blob_index >= num_blobs) debug_str +=
" blob == nullptr";
465 correct_segmentation_cols_.
clear();
466 correct_segmentation_rows_.
clear();
◆ SetupNormTruthWord()
void BlamerBundle::SetupNormTruthWord |
( |
const DENORM & |
denorm | ) |
|
Definition at line 153 of file blamer.cpp.
155 norm_box_tolerance_ = kBlamerBoxTolerance * denorm.
x_scale();
160 for (
int b = 0; b < truth_word_.
length(); ++b) {
162 topleft.
x = box.
left();
163 topleft.
y = box.
top();
168 TBOX norm_box(norm_topleft.
x, norm_botright.
y,
169 norm_botright.
x, norm_topleft.
y);
◆ SetWordTruth()
void BlamerBundle::SetWordTruth |
( |
const UNICHARSET & |
unicharset, |
|
|
const char * |
truth_str, |
|
|
const TBOX & |
word_box |
|
) |
| |
Definition at line 74 of file blamer.cpp.
77 truth_has_char_boxes_ =
false;
81 unicharset.
encode_string(truth_str,
false, &encoding, &lengths,
nullptr);
83 for (
int i = 0; i < encoding.
size(); total_length += lengths[i++]) {
84 STRING uch(truth_str + total_length);
85 uch.truncate_at(lengths[i] - total_length);
◆ SplitBundle()
void BlamerBundle::SplitBundle |
( |
int |
word1_right, |
|
|
int |
word2_left, |
|
|
bool |
debug, |
|
|
BlamerBundle * |
bundle1, |
|
|
BlamerBundle * |
bundle2 |
|
) |
| const |
Definition at line 177 of file blamer.cpp.
183 int begin2_truth_index = -1;
185 truth_has_char_boxes_) {
186 debug_str =
"Looking for truth split at";
189 debug_str +=
"\nnorm_truth_word boxes:\n";
190 if (norm_truth_word_.
length() > 1) {
192 for (b = 1; b < norm_truth_word_.
length(); ++b) {
194 if ((abs(word1_right - norm_truth_word_.
BlobBox(b - 1).
right()) <
195 norm_box_tolerance_) &&
196 (abs(word2_left - norm_truth_word_.
BlobBox(b).
left()) <
197 norm_box_tolerance_)) {
198 begin2_truth_index = b;
199 debug_str +=
"Split found";
208 if (begin2_truth_index > 0) {
209 bundle1->truth_has_char_boxes_ =
true;
210 bundle1->norm_box_tolerance_ = norm_box_tolerance_;
211 bundle2->truth_has_char_boxes_ =
true;
212 bundle2->norm_box_tolerance_ = norm_box_tolerance_;
214 for (b = 0; b < norm_truth_word_.
length(); ++b) {
215 if (b == begin2_truth_index) curr_bb = bundle2;
218 curr_bb->truth_text_.
push_back(truth_text_[b]);
224 debug_str +=
"Truth split not found";
225 debug_str += truth_has_char_boxes_ ?
226 "\n" :
" (no truth char boxes)\n";
◆ TruthString()
STRING BlamerBundle::TruthString |
( |
| ) |
const |
|
inline |
Definition at line 114 of file blamer.h.
116 for (
int i = 0; i < truth_text_.
length(); ++i)
117 truth_str += truth_text_[i];
◆ UpdateBestRating()
void BlamerBundle::UpdateBestRating |
( |
float |
rating | ) |
|
|
inline |
Definition at line 136 of file blamer.h.
137 if (rating < best_correctly_segmented_rating_)
138 best_correctly_segmented_rating_ = rating;
The documentation for this struct was generated from the following files:
bool x_almost_equal(const TBOX &box, int tolerance) const
void CopyTruth(const BlamerBundle &other)
const char * string() const
UNICHAR_ID unichar_id() const
void print_to_str(STRING *str) const
WERD_CHOICE * best_choice
BlamerBundle * blamer_bundle
void add_str_int(const char *str, int number)
bool encode_string(const char *str, bool give_up_on_failure, GenericVector< UNICHAR_ID > *encoding, GenericVector< char > *lengths, int *encoded_length) const
const char * id_to_unichar(UNICHAR_ID id) const
GenericVector< TBLOB * > blobs
ParamsTrainingHypothesis & AddHypothesis(const ParamsTrainingHypothesis &other)
STRING TruthString() const
UNICHAR_ID unichar_id(int index) const
DLLSYM void tprintf(const char *format,...)
UNICHAR_ID unichar_to_id(const char *const unichar_repr) const
void NormTransform(const DENORM *first_norm, const TPOINT &pt, TPOINT *transformed) const
BLOB_CHOICE_LIST * GetBlobChoices(int index) const
bool Classified(int col, int row, int wildcard_id) const
static const char * permuter_name(uint8_t permuter)
void InsertBox(int index, const TBOX &box)
void FillDebugString(const STRING &msg, const WERD_CHOICE *choice, STRING *debug)
const char * get_normed_unichar(UNICHAR_ID unichar_id) const
const TBOX & BlobBox(int index) const
const STRING & debug() const
void StartHypothesisList()
const CHAR_FRAGMENT * get_fragment(UNICHAR_ID unichar_id) const
const UNICHARSET * unicharset() const
@ IRR_CLASS_OLD_LM_TRADEOFF
void CopyResults(const BlamerBundle &other)
bool ChoiceIsCorrect(const WERD_CHOICE *word_choice) const
TBOX bounding_box() const
static const float kBadRating
void add_str_double(const char *str, double number)
const char *const kIncorrectResultReasonNames[]
void string_and_lengths(STRING *word_str, STRING *word_lengths_str) const