MCPcopy Create free account
hub / github.com/creatale/node-dv / cube_recognize

Method cube_recognize

deps/tesseract/ccmain/cube_control.cpp:334–413  ·  view source on GitHub ↗

* @name cube_recognize * * Call cube on the current word, and write the result to word. * Sets up a fake result and returns false if something goes wrong. */

Source from the content-addressed store, hash-verified

332 * Sets up a fake result and returns false if something goes wrong.
333 */
334bool Tesseract::cube_recognize(CubeObject *cube_obj, BLOCK* block,
335 WERD_RES *word) {
336 // Run cube
337 WordAltList *cube_alt_list = cube_obj->RecognizeWord();
338 if (!cube_alt_list || cube_alt_list->AltCount() <= 0) {
339 if (cube_debug_level > 0) {
340 tprintf("Cube returned nothing for word at:");
341 word->word->bounding_box().print();
342 }
343 word->SetupFake(unicharset);
344 return false;
345 }
346
347 // Get cube's best result and its probability, mapped to tesseract's
348 // certainty range
349 char_32 *cube_best_32 = cube_alt_list->Alt(0);
350 double cube_prob = CubeUtils::Cost2Prob(cube_alt_list->AltCost(0));
351 float cube_certainty = convert_prob_to_tess_certainty(cube_prob);
352 string cube_best_str;
353 CubeUtils::UTF32ToUTF8(cube_best_32, &cube_best_str);
354
355 // Retrieve Cube's character bounding boxes and CharSamples,
356 // corresponding to the most recent call to RecognizeWord().
357 Boxa *char_boxes = NULL;
358 CharSamp **char_samples = NULL;;
359 int num_chars;
360 if (!extract_cube_state(cube_obj, &num_chars, &char_boxes, &char_samples)
361 && cube_debug_level > 0) {
362 tprintf("Cube WARNING (Tesseract::cube_recognize): Cannot extract "
363 "cube state.\n");
364 word->SetupFake(unicharset);
365 return false;
366 }
367
368 // Convert cube's character bounding boxes to a BoxWord.
369 BoxWord cube_box_word;
370 TBOX tess_word_box = word->word->bounding_box();
371 if (word->denorm.block() != NULL)
372 tess_word_box.rotate(word->denorm.block()->re_rotation());
373 bool box_word_success = create_cube_box_word(char_boxes, num_chars,
374 tess_word_box,
375 &cube_box_word);
376 boxaDestroy(&char_boxes);
377 if (!box_word_success) {
378 if (cube_debug_level > 0) {
379 tprintf("Cube WARNING (Tesseract::cube_recognize): Could not "
380 "create cube BoxWord\n");
381 }
382 word->SetupFake(unicharset);
383 return false;
384 }
385
386 // Fill tesseract result's fields with cube results
387 fill_werd_res(cube_box_word, cube_best_str.c_str(), word);
388
389 // Create cube's best choice.
390 BLOB_CHOICE** choices = new BLOB_CHOICE*[num_chars];
391 for (int i = 0; i < num_chars; ++i) {

Callers

nothing calls this directly

Calls 15

boxaDestroyFunction · 0.85
RecognizeWordMethod · 0.80
AltCountMethod · 0.80
SetupFakeMethod · 0.80
AltCostMethod · 0.80
re_rotationMethod · 0.80
UnicharIDMethod · 0.80
CharacterSetMethod · 0.80
StrLabelMethod · 0.80
FakeClassifyWordMethod · 0.80
ratingMethod · 0.80

Tested by

no test coverage detected