12 #include "config_auto.h"
15 #include "allheaders.h"
30 static float convert_prob_to_tess_certainty(
float prob) {
31 return (prob - 1.0) * 20.0;
50 boxGetGeometry(char_box, &left, &top, &width, &height);
51 left += word_box.
left() - x_offset;
54 bottom = top - height;
55 return TBOX(left, bottom, right, top);
71 tprintf(
"Cube WARNING (extract_cube_state): Invalid cube object "
72 "passed to extract_cube_state\n");
81 if (!cube_search_obj) {
83 tprintf(
"Cube WARNING (Extract_cube_state): Could not retrieve "
84 "cube's search object in extract_cube_state.\n");
89 if (!beam_search_obj) {
91 tprintf(
"Cube WARNING (Extract_cube_state): Could not retrieve "
92 "cube's beam search object in extract_cube_state.\n");
100 *char_samples = beam_search_obj->
BackTrack(
101 cube_search_obj, best_node_index, num_chars,
NULL, char_boxes);
122 tprintf(
"Cube WARNING (create_cube_box_word): Invalid box_word.\n");
130 for (
int i = 0; i < num_chars; ++i) {
131 Box* char_box = boxaGetBox(char_boxes, i, L_CLONE);
132 if (x_offset < 0 || char_box->x < x_offset) {
133 x_offset = char_box->x;
135 boxDestroy(&char_box);
138 for (
int i = 0; i < num_chars; ++i) {
139 Box* char_box = boxaGetBox(char_boxes, i, L_CLONE);
141 boxDestroy(&char_box);
161 if (cube_cntxt_ ==
NULL) {
163 tprintf(
"Cube WARNING (Tesseract::init_cube_objects()): Failed to "
164 "instantiate CubeRecoContext\n");
175 if (tess_cube_combiner_ !=
NULL) {
176 delete tess_cube_combiner_;
177 tess_cube_combiner_ =
NULL;
180 tprintf(
"Cube ERROR (Failed to instantiate TesseractCubeCombiner\n");
194 if (page_res ==
NULL || tess_cube_combiner_ ==
NULL)
205 int combiner_run_thresh = convert_prob_to_tess_certainty(
218 NULL,
false,
false,
false,
223 if (cube_obj !=
NULL)
247 if (!cube_binary_ || !cube_cntxt_) {
249 tprintf(
"Tesseract::run_cube(): NULL binary image.\n");
260 tprintf(
"Cube can't process rotated word at:");
267 cube_cntxt_, cube_binary_, word_box.
left(),
268 pixGetHeight(cube_binary_) - word_box.
top(),
285 float combiner_prob = tess_cube_combiner_->
CombineResults(tess_word,
295 tprintf(
"Combiner prob = %g vs threshold %g\n",
313 tprintf(
"Cube INFO: tesseract result replaced by cube: %s -> %s\n",
330 if (!cube_alt_list || cube_alt_list->
AltCount() <= 0) {
332 tprintf(
"Cube returned nothing for word at:");
341 char_32 *cube_best_32 = cube_alt_list->
Alt(0);
343 float cube_certainty = convert_prob_to_tess_certainty(cube_prob);
344 string cube_best_str;
349 Boxa *char_boxes =
NULL;
354 tprintf(
"Cube WARNING (Tesseract::cube_recognize): Cannot extract "
368 boxaDestroy(&char_boxes);
369 if (!box_word_success) {
371 tprintf(
"Cube WARNING (Tesseract::cube_recognize): Could not "
372 "create cube BoxWord\n");
383 for (
int i = 0; i < num_chars; ++i) {
386 choices[i] =
new BLOB_CHOICE(uch_id, -cube_certainty, cube_certainty,
393 delete [] char_samples;
399 tprintf(
"Cube result: %s r=%g, c=%g\n",
414 const char* cube_best_str,
419 tess_werd_res->
word);
void SetupFake(const UNICHARSET &uch)
void ConsumeWordResults(WERD_RES *word)
void run_cube_combiner(PAGE_RES *page_res)
TBOX char_box_to_tbox(Box *char_box, TBOX word_box, int x_offset)
tesseract::BoxWord * box_word
double CombinerClassifierThresh() const
void set_text(const char *new_text)
void set_certainty(float new_val)
CubeSearchObject * SrchObj() const
BeamSearch * BeamObj() const
void fill_werd_res(const BoxWord &cube_box_word, const char *cube_best_str, WERD_RES *tess_werd_res)
float CombineResults(WERD_RES *tess_res, CubeObject *cube_obj)
WERD_CHOICE * best_choice
bool create_cube_box_word(Boxa *char_boxes, int num_chars, TBOX word_box, BoxWord *box_word)
int AltCost(int alt_idx) const
TBOX bounding_box() const
void InitForRetryRecognition(const WERD_RES &source)
WordAltList * RecognizeWord(LangModel *lang_mod=NULL)
void ClipToOriginalWord(const BLOCK *block, WERD *original_word)
const STRING & unichar_string() const
BLOCK_RES * block() const
WERD_RES * restart_page()
void FakeClassifyWord(int blob_count, BLOB_CHOICE **choices)
bool set_unichars_in_script_order(bool in_script_order)
FCOORD re_rotation() const
bool extract_cube_state(CubeObject *cube_obj, int *num_chars, Boxa **char_boxes, CharSamp ***char_samples)
bool init_cube_objects(bool load_combiner, TessdataManager *tessdata_manager)
tesseract::Tesseract * tesseract
int UnicharID(const char_32 *str) const
TuningParams * Params() const
void cube_word_pass1(BLOCK *block, ROW *row, WERD_RES *word)
char_32 * Alt(int alt_idx)
static double Cost2Prob(int cost)
static void UTF32ToUTF8(const char_32 *utf32_str, string *str)
double CombinerRunThresh() const
CharSet * CharacterSet() const
bool tess_acceptable_word(WERD_RES *word)
bool SetupForRecognition(const UNICHARSET &unicharset_in, tesseract::Tesseract *tesseract, Pix *pix, int norm_mode, const TBOX *norm_box, bool numeric_mode, bool use_body_size, bool allow_detailed_fx, ROW *row, const BLOCK *block)
bool cube_recognize(CubeObject *cube_obj, BLOCK *block, WERD_RES *word)
void InsertBox(int index, const TBOX &box)
static CubeRecoContext * Create(Tesseract *tess_obj, TessdataManager *tessdata_manager, UNICHARSET *tess_unicharset)
void cube_combine_word(CubeObject *cube_obj, WERD_RES *cube_word, WERD_RES *tess_word)
const BLOCK * block() const
const char * string() const
int BestPresortedNodeIndex() const
POLY_BLOCK * poly_block() const
CubeObject * cube_recognize_word(BLOCK *block, WERD_RES *word)
void set_rating(float new_val)
CharSamp ** BackTrack(SearchObject *srch_obj, int node_index, int *char_cnt, char_32 **str32, Boxa **char_boxes) const
void rotate(const FCOORD &vec)