20#ifndef TESSERACT_CCSTRUCT_BLAMER_H_
21#define TESSERACT_CCSTRUCT_BLAMER_H_
24# include "config_auto.h"
27#ifndef DISABLED_LEGACY_ENGINE
52static const int16_t kBlamerBoxTolerance = 5;
110 : truth_has_char_boxes_(false)
112 , lattice_data_(nullptr) {
120 delete[] lattice_data_;
125 std::string truth_str;
126 for (
auto &text : truth_text_) {
132 return incorrect_result_reason_;
138 return debug_.length() > 0 || misadaption_debug_.length() > 0;
144 return misadaption_debug_;
147 if (rating < best_correctly_segmented_rating_) {
148 best_correctly_segmented_rating_ = rating;
152 return correct_segmentation_cols_.size();
157 return correct_segmentation_cols_[index] == coord.
col &&
158 correct_segmentation_rows_[index] == coord.
row;
161 best_choice_is_dict_and_top_choice_ =
value;
164 return lattice_data_;
167 return lattice_size_;
170 lattice_size_ = size;
171 delete[] lattice_data_;
172 lattice_data_ =
new char[lattice_size_];
173 memcpy(lattice_data_, data, lattice_size_);
175#ifndef DISABLED_LEGACY_ENGINE
177 return params_training_bundle_;
200 norm_box_tolerance_ = 0;
205 segsearch_is_looking_for_blame_ =
false;
207 correct_segmentation_cols_.clear();
208 correct_segmentation_rows_.clear();
209 best_choice_is_dict_and_top_choice_ =
false;
210 delete[] lattice_data_;
211 lattice_data_ =
nullptr;
215 truth_has_char_boxes_ = other.truth_has_char_boxes_;
216 truth_word_ = other.truth_word_;
217 truth_text_ = other.truth_text_;
218 incorrect_result_reason_ = (other.
NoTruth() ? other.incorrect_result_reason_ :
IRR_CORRECT);
221 norm_truth_word_ = other.norm_truth_word_;
222 norm_box_tolerance_ = other.norm_box_tolerance_;
223 incorrect_result_reason_ = other.incorrect_result_reason_;
224 segsearch_is_looking_for_blame_ = other.segsearch_is_looking_for_blame_;
225 best_correctly_segmented_rating_ = other.best_correctly_segmented_rating_;
226 correct_segmentation_cols_ = other.correct_segmentation_cols_;
227 correct_segmentation_rows_ = other.correct_segmentation_rows_;
228 best_choice_is_dict_and_top_choice_ = other.best_choice_is_dict_and_top_choice_;
229 if (other.lattice_data_ !=
nullptr) {
230 lattice_data_ =
new char[other.lattice_size_];
231 memcpy(lattice_data_, other.lattice_data_, other.lattice_size_);
232 lattice_size_ = other.lattice_size_;
234 lattice_data_ =
nullptr;
257 const BLOB_CHOICE_LIST &choices,
bool debug);
269 bool valid_permuter,
bool debug);
278 double max_char_wh_ratio,
WERD_RES *word_res);
297 incorrect_result_reason_ = irr;
299 debug_ +=
" to blame: ";
302 tprintf(
"SetBlame(): %s", debug_.c_str());
308 bool truth_has_char_boxes_;
312 bool segsearch_is_looking_for_blame_;
315 bool best_choice_is_dict_and_top_choice_;
317 int norm_box_tolerance_;
325 std::vector<std::string> truth_text_;
331 std::string misadaption_debug_;
334 std::vector<int> correct_segmentation_cols_;
335 std::vector<int> correct_segmentation_rows_;
338 float best_correctly_segmented_rating_;
343#ifndef DISABLED_LEGACY_ENGINE
void tprintf(const char *format,...)
@ IRR_CLASS_OLD_LM_TRADEOFF
bool GuidedSegsearchNeeded(const WERD_CHOICE *best_choice) const
bool GuidedSegsearchStillGoing() const
BlamerBundle(const BlamerBundle &other)
void set_lattice_data(const char *data, int size)
static const char * IncorrectReasonName(IncorrectResultReason irr)
std::string TruthString() const
void FinishSegSearch(const WERD_CHOICE *best_choice, bool debug, std::string &debug_str)
static void LastChanceBlame(bool debug, WERD_RES *word)
const std::string & misadaption_debug() const
void set_best_choice_is_dict_and_top_choice(bool value)
void SplitBundle(int word1_right, int word2_left, bool debug, BlamerBundle *bundle1, BlamerBundle *bundle2) const
void AddHypothesis(const tesseract::ParamsTrainingHypothesis &hypo)
const tesseract::ParamsTrainingBundle & params_training_bundle() const
bool HasDebugInfo() const
void UpdateBestRating(float rating)
const std::string & debug() const
void JoinBlames(const BlamerBundle &bundle1, const BlamerBundle &bundle2, bool debug)
bool MatrixPositionCorrect(int index, const MATRIX_COORD &coord)
void SetWordTruth(const UNICHARSET &unicharset, const char *truth_str, const TBOX &word_box)
void SetChopperBlame(const WERD_RES *word, bool debug)
bool ChoiceIsCorrect(const WERD_CHOICE *word_choice) const
void InitForSegSearch(const WERD_CHOICE *best_choice, MATRIX *ratings, UNICHAR_ID wildcard_id, bool debug, std::string &debug_str, tesseract::LMPainPoints *pain_points, double max_char_wh_ratio, WERD_RES *word_res)
void SetMisAdaptionDebug(const WERD_CHOICE *best_choice, bool debug)
const char * lattice_data() const
void BlameClassifierOrLangModel(const WERD_RES *word, const UNICHARSET &unicharset, bool valid_permuter, bool debug)
void CopyTruth(const BlamerBundle &other)
void CopyResults(const BlamerBundle &other)
const char * IncorrectReason() const
void SetSymbolTruth(const UNICHARSET &unicharset, const char *char_str, const TBOX &char_box)
void FillDebugString(const std::string &msg, const WERD_CHOICE *choice, std::string &debug)
int correct_segmentation_length() const
void BlameClassifier(const UNICHARSET &unicharset, const TBOX &blob_box, const BLOB_CHOICE_LIST &choices, bool debug)
void SetupNormTruthWord(const DENORM &denorm)
void SetupCorrectSegmentation(const TWERD *word, bool debug)
IncorrectResultReason incorrect_result_reason() const
ParamsTrainingHypothesis & AddHypothesis(const ParamsTrainingHypothesis &other)
static const float kBadRating