tesseract  3.05.02
fixspace.cpp File Reference
#include <ctype.h>
#include "reject.h"
#include "statistc.h"
#include "control.h"
#include "fixspace.h"
#include "genblob.h"
#include "tessvars.h"
#include "tessbox.h"
#include "globals.h"
#include "tesseractclass.h"

Go to the source code of this file.

Namespaces

 tesseract
 

Macros

#define PERFECT_WERDS   999
 
#define MAXSPACING   128 /*max expected spacing in pix */
 

Functions

void initialise_search (WERD_RES_LIST &src_list, WERD_RES_LIST &new_list)
 
transform_to_next_perm()

Examines the current word list to find the smallest word gap size. Then walks the word list closing any gaps of this size by either inserted new combination words, or extending existing ones.

The routine COULD be limited to stop it building words longer than N blobs.

If there are no more gaps then it DELETES the entire list and returns the empty list to cause termination.

void transform_to_next_perm (WERD_RES_LIST &words)
 
void fixspace_dbg (WERD_RES *word)
 

Macro Definition Documentation

◆ MAXSPACING

#define MAXSPACING   128 /*max expected spacing in pix */

Definition at line 34 of file fixspace.cpp.

◆ PERFECT_WERDS

#define PERFECT_WERDS   999

Definition at line 33 of file fixspace.cpp.

Function Documentation

◆ fixspace_dbg()

void fixspace_dbg ( WERD_RES word)

Definition at line 795 of file fixspace.cpp.

795  {
796  TBOX box = word->word->bounding_box();
797  BOOL8 show_map_detail = FALSE;
798  inT16 i;
799 
800  box.print();
801  tprintf(" \"%s\" ", word->best_choice->unichar_string().string());
802  tprintf("Blob count: %d (word); %d/%d (rebuild word)\n",
803  word->word->cblob_list()->length(),
804  word->rebuild_word->NumBlobs(),
805  word->box_word->length());
806  word->reject_map.print(debug_fp);
807  tprintf("\n");
808  if (show_map_detail) {
809  tprintf("\"%s\"\n", word->best_choice->unichar_string().string());
810  for (i = 0; word->best_choice->unichar_string()[i] != '\0'; i++) {
811  tprintf("**** \"%c\" ****\n", word->best_choice->unichar_string()[i]);
812  word->reject_map[i].full_print(debug_fp);
813  }
814  }
815 
816  tprintf("Tess Accepted: %s\n", word->tess_accepted ? "TRUE" : "FALSE");
817  tprintf("Done flag: %s\n\n", word->done ? "TRUE" : "FALSE");
818 }
BOOL8 tess_accepted
Definition: pageres.h:280
void print(FILE *fp)
Definition: rejctmap.cpp:394
short inT16
Definition: host.h:33
TWERD * rebuild_word
Definition: pageres.h:244
FILE * debug_fp
Definition: tessvars.cpp:24
const STRING & unichar_string() const
Definition: ratngs.h:525
void full_print(FILE *fp)
Definition: rejctmap.cpp:406
int length() const
Definition: boxword.h:85
WERD_CHOICE * best_choice
Definition: pageres.h:219
unsigned char BOOL8
Definition: host.h:46
tesseract::BoxWord * box_word
Definition: pageres.h:250
const char * string() const
Definition: strngs.cpp:201
#define FALSE
Definition: capi.h:46
void print() const
Definition: rect.h:270
int NumBlobs() const
Definition: blobs.h:425
#define tprintf(...)
Definition: tprintf.h:31
Definition: rect.h:30
WERD * word
Definition: pageres.h:175
BOOL8 done
Definition: pageres.h:282
C_BLOB_LIST * cblob_list()
Definition: werd.h:100
TBOX bounding_box() const
Definition: werd.cpp:160
REJMAP reject_map
Definition: pageres.h:271

◆ initialise_search()

void initialise_search ( WERD_RES_LIST &  src_list,
WERD_RES_LIST &  new_list 
)

Definition at line 177 of file fixspace.cpp.

177  {
178  WERD_RES_IT src_it(&src_list);
179  WERD_RES_IT new_it(&new_list);
180  WERD_RES *src_wd;
181  WERD_RES *new_wd;
182 
183  for (src_it.mark_cycle_pt(); !src_it.cycled_list(); src_it.forward()) {
184  src_wd = src_it.data();
185  if (!src_wd->combination) {
186  new_wd = WERD_RES::deep_copy(src_wd);
187  new_wd->combination = FALSE;
188  new_wd->part_of_combo = FALSE;
189  new_it.add_after_then_move(new_wd);
190  }
191  }
192 }
BOOL8 combination
Definition: pageres.h:318
static WERD_RES * deep_copy(const WERD_RES *src)
Definition: pageres.h:633
BOOL8 part_of_combo
Definition: pageres.h:319
#define FALSE
Definition: capi.h:46

◆ transform_to_next_perm()

void transform_to_next_perm ( WERD_RES_LIST &  words)

Definition at line 372 of file fixspace.cpp.

372  {
373  WERD_RES_IT word_it(&words);
374  WERD_RES_IT prev_word_it(&words);
375  WERD_RES *word;
376  WERD_RES *prev_word;
377  WERD_RES *combo;
378  WERD *copy_word;
379  inT16 prev_right = -MAX_INT16;
380  TBOX box;
381  inT16 gap;
382  inT16 min_gap = MAX_INT16;
383 
384  for (word_it.mark_cycle_pt(); !word_it.cycled_list(); word_it.forward()) {
385  word = word_it.data();
386  if (!word->part_of_combo) {
387  box = word->word->bounding_box();
388  if (prev_right > -MAX_INT16) {
389  gap = box.left() - prev_right;
390  if (gap < min_gap)
391  min_gap = gap;
392  }
393  prev_right = box.right();
394  }
395  }
396  if (min_gap < MAX_INT16) {
397  prev_right = -MAX_INT16; // back to start
398  word_it.set_to_list(&words);
399  // Note: we can't use cycle_pt due to inserted combos at start of list.
400  for (; (prev_right == -MAX_INT16) || !word_it.at_first();
401  word_it.forward()) {
402  word = word_it.data();
403  if (!word->part_of_combo) {
404  box = word->word->bounding_box();
405  if (prev_right > -MAX_INT16) {
406  gap = box.left() - prev_right;
407  if (gap <= min_gap) {
408  prev_word = prev_word_it.data();
409  if (prev_word->combination) {
410  combo = prev_word;
411  } else {
412  /* Make a new combination and insert before
413  * the first word being joined. */
414  copy_word = new WERD;
415  *copy_word = *(prev_word->word);
416  // deep copy
417  combo = new WERD_RES(copy_word);
418  combo->combination = TRUE;
419  combo->x_height = prev_word->x_height;
420  prev_word->part_of_combo = TRUE;
421  prev_word_it.add_before_then_move(combo);
422  }
423  combo->word->set_flag(W_EOL, word->word->flag(W_EOL));
424  if (word->combination) {
425  combo->word->join_on(word->word);
426  // Move blobs to combo
427  // old combo no longer needed
428  delete word_it.extract();
429  } else {
430  // Copy current wd to combo
431  combo->copy_on(word);
432  word->part_of_combo = TRUE;
433  }
434  combo->done = FALSE;
435  combo->ClearResults();
436  } else {
437  prev_word_it = word_it; // catch up
438  }
439  }
440  prev_right = box.right();
441  }
442  }
443  } else {
444  words.clear(); // signal termination
445  }
446 }
BOOL8 combination
Definition: pageres.h:318
void ClearResults()
Definition: pageres.cpp:1141
#define TRUE
Definition: capi.h:45
short inT16
Definition: host.h:33
Definition: werd.h:36
void join_on(WERD *other)
Definition: werd.cpp:211
float x_height
Definition: pageres.h:295
BOOL8 part_of_combo
Definition: pageres.h:319
#define MAX_INT16
Definition: host.h:52
BOOL8 flag(WERD_FLAGS mask) const
Definition: werd.h:128
Definition: werd.h:60
#define FALSE
Definition: capi.h:46
inT16 left() const
Definition: rect.h:68
Definition: rect.h:30
inT16 right() const
Definition: rect.h:75
WERD * word
Definition: pageres.h:175
void copy_on(WERD_RES *word_res)
Definition: pageres.h:644
BOOL8 done
Definition: pageres.h:282
void set_flag(WERD_FLAGS mask, BOOL8 value)
Definition: werd.h:129
TBOX bounding_box() const
Definition: werd.cpp:160