25 #include "allheaders.h" 40 static float convert_prob_to_tess_certainty(
float prob) {
41 return (prob - 1.0) * 20.0;
60 boxGetGeometry(char_box, &left, &top, &width, &height);
61 left += word_box.
left() - x_offset;
64 bottom = top - height;
65 return TBOX(left, bottom, right, top);
81 tprintf(
"Cube WARNING (extract_cube_state): Invalid cube object " 82 "passed to extract_cube_state\n");
91 if (!cube_search_obj) {
93 tprintf(
"Cube WARNING (Extract_cube_state): Could not retrieve " 94 "cube's search object in extract_cube_state.\n");
99 if (!beam_search_obj) {
101 tprintf(
"Cube WARNING (Extract_cube_state): Could not retrieve " 102 "cube's beam search object in extract_cube_state.\n");
110 *char_samples = beam_search_obj->
BackTrack(
111 cube_search_obj, best_node_index, num_chars, NULL, char_boxes);
132 tprintf(
"Cube WARNING (create_cube_box_word): Invalid box_word.\n");
140 for (
int i = 0; i < num_chars; ++i) {
141 Box* char_box = boxaGetBox(char_boxes, i, L_CLONE);
142 if (x_offset < 0 || char_box->x < x_offset) {
143 x_offset = char_box->x;
145 boxDestroy(&char_box);
148 for (
int i = 0; i < num_chars; ++i) {
149 Box* char_box = boxaGetBox(char_boxes, i, L_CLONE);
151 boxDestroy(&char_box);
171 if (cube_cntxt_ == NULL) {
173 tprintf(
"Cube WARNING (Tesseract::init_cube_objects()): Failed to " 174 "instantiate CubeRecoContext\n");
185 delete tess_cube_combiner_;
186 tess_cube_combiner_ = NULL;
188 tprintf(
"Cube ERROR (Failed to instantiate TesseractCubeCombiner\n");
202 if (page_res == NULL || tess_cube_combiner_ == NULL)
213 int combiner_run_thresh = convert_prob_to_tess_certainty(
226 NULL,
false,
false,
false,
231 if (cube_obj != NULL)
255 if (!cube_binary_ || !cube_cntxt_) {
257 tprintf(
"Tesseract::run_cube(): NULL binary image.\n");
262 if (block != NULL && (block->
re_rotation().
x() != 1.0f ||
268 tprintf(
"Cube can't process rotated word at:");
275 cube_cntxt_, cube_binary_, word_box.
left(),
276 pixGetHeight(cube_binary_) - word_box.
top(),
293 float combiner_prob = tess_cube_combiner_->
CombineResults(tess_word,
303 tprintf(
"Combiner prob = %g vs threshold %g\n",
321 tprintf(
"Cube INFO: tesseract result replaced by cube: %s -> %s\n",
338 if (!cube_alt_list || cube_alt_list->
AltCount() <= 0) {
340 tprintf(
"Cube returned nothing for word at:");
349 char_32 *cube_best_32 = cube_alt_list->
Alt(0);
351 float cube_certainty = convert_prob_to_tess_certainty(cube_prob);
352 string cube_best_str;
357 Boxa *char_boxes = NULL;
362 tprintf(
"Cube WARNING (Tesseract::cube_recognize): Cannot extract " 376 boxaDestroy(&char_boxes);
377 if (!box_word_success) {
379 tprintf(
"Cube WARNING (Tesseract::cube_recognize): Could not " 380 "create cube BoxWord\n");
391 for (
int i = 0; i < num_chars; ++i) {
394 choices[i] =
new BLOB_CHOICE(uch_id, -cube_certainty, cube_certainty,
401 delete [] char_samples;
407 tprintf(
"Cube result: %s r=%g, c=%g\n",
422 const char* cube_best_str,
427 tess_werd_res->
word);
bool init_cube_objects(bool load_combiner, TessdataManager *tessdata_manager)
CubeObject * cube_recognize_word(BLOCK *block, WERD_RES *word)
void rotate(const FCOORD &vec)
bool create_cube_box_word(Boxa *char_boxes, int num_chars, TBOX word_box, BoxWord *box_word)
int UnicharID(const char_32 *str) const
void InsertBox(int index, const TBOX &box)
const STRING & unichar_string() const
void set_rating(float new_val)
bool tess_acceptable_word(WERD_RES *word)
bool cube_recognize(CubeObject *cube_obj, BLOCK *block, WERD_RES *word)
double CombinerClassifierThresh() const
CharSamp ** BackTrack(SearchObject *srch_obj, int node_index, int *char_cnt, char_32 **str32, Boxa **char_boxes) const
void ConsumeWordResults(WERD_RES *word)
bool set_unichars_in_script_order(bool in_script_order)
double CombinerRunThresh() const
char_32 * Alt(int alt_idx)
WERD_RES * restart_page()
bool extract_cube_state(CubeObject *cube_obj, int *num_chars, Boxa **char_boxes, CharSamp ***char_samples)
WERD_CHOICE * best_choice
void ClipToOriginalWord(const BLOCK *block, WERD *original_word)
void fill_werd_res(const BoxWord &cube_box_word, const char *cube_best_str, WERD_RES *tess_werd_res)
static CubeRecoContext * Create(Tesseract *tess_obj, TessdataManager *tessdata_manager, UNICHARSET *tess_unicharset)
void run_cube_combiner(PAGE_RES *page_res)
static double Cost2Prob(int cost)
POLY_BLOCK * poly_block() const
void SetupFake(const UNICHARSET &uch)
TessdataManager tessdata_manager
void cube_word_pass1(BLOCK *block, ROW *row, WERD_RES *word)
tesseract::BoxWord * box_word
FCOORD re_rotation() const
const char * string() const
static void UTF32ToUTF8(const char_32 *utf32_str, string *str)
void set_certainty(float new_val)
TuningParams * Params() const
const BLOCK * block() const
int BestPresortedNodeIndex() const
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)
WordAltList * RecognizeWord(LangModel *lang_mod=NULL)
BLOCK_RES * block() const
void InitForRetryRecognition(const WERD_RES &source)
CharSet * CharacterSet() const
void FakeClassifyWord(int blob_count, BLOB_CHOICE **choices)
float CombineResults(WERD_RES *tess_res, CubeObject *cube_obj)
BeamSearch * BeamObj() const
tesseract::Tesseract * tesseract
int AltCost(int alt_idx) const
TBOX char_box_to_tbox(Box *char_box, TBOX word_box, int x_offset)
CubeSearchObject * SrchObj() const
TBOX bounding_box() const
void cube_combine_word(CubeObject *cube_obj, WERD_RES *cube_word, WERD_RES *tess_word)
void set_text(const char *new_text)