⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pgedit.cpp

📁 一OCR的相关资料。.希望对研究OCR的朋友有所帮助.
💻 CPP
📖 第 1 页 / 共 5 页
字号:
 * Scale by width or height to generate the largest image **********************************************************************/float re_scale_and_move_bln_word(                  //put bln word in       box                                 WERD *norm_word,  //BL normalised word                                 const BOX &box    //destination box                                ) {  BOX norm_box = norm_word->bounding_box ();  float width_scale_factor;  float height_scale_factor;  float selected_scale_factor;  width_scale_factor = box.width () / (float) norm_box.width ();  height_scale_factor = box.height () / (float) ASC_HEIGHT;  if ((ASC_HEIGHT * width_scale_factor) <= box.height ())    selected_scale_factor = width_scale_factor;  else    selected_scale_factor = height_scale_factor;  norm_word->scale (selected_scale_factor);  norm_word->move (ICOORD ((box.left () + box.width () / 2), box.bottom ()));  return selected_scale_factor;}/********************************************************************** * re_segment_word() * * If all selected blobs are in the same row, remove them from their current * word(s) and put them in a new word.  Insert the new word in the row at the * appropriate point. Delete any empty words. * **********************************************************************/void re_segment_word(                         //break/join words                     BLOCK_LIST *block_list,  //blocks to check                     BOX &selection_box) {  BLOCK_IT block_it(block_list);  BLOCK *block;  BLOCK *block_to_process = NULL;  ROW_IT row_it;  ROW *row;  ROW *row_to_process = NULL;  WERD_IT word_it;  WERD *word;  WERD *new_word = NULL;  BOOL8 polyg = false;  PBLOB_IT blob_it;  PBLOB_LIST dummy;  // Just to initialize new_blob_it.  PBLOB_IT new_blob_it = &dummy;  PBLOB *blob;  /* Find row to process - error if selections from more than one row */  for (block_it.mark_cycle_pt ();  !block_it.cycled_list (); block_it.forward ()) {    block = block_it.data ();    if (block->bounding_box ().overlap (selection_box)) {      row_it.set_to_list (block->row_list ());      for (row_it.mark_cycle_pt ();      !row_it.cycled_list (); row_it.forward ()) {        row = row_it.data ();        if (row->bounding_box ().overlap (selection_box)) {          if (row_to_process == NULL) {            block_to_process = block;            row_to_process = row;          }          else {            command_window->              msg ("Cant resegment words in more than one row");            return;          }        }      }    }  }  /* Continue with row_to_process */  word_it.set_to_list (row_to_process->word_list ());  for (word_it.mark_cycle_pt (); !word_it.cycled_list (); word_it.forward ()) {    word = word_it.data ();    polyg = word->flag (W_POLYGON);    if (word->bounding_box ().overlap (selection_box)) {      blob_it.set_to_list (word->gblob_list ());      for (blob_it.mark_cycle_pt ();      !blob_it.cycled_list (); blob_it.forward ()) {        blob = blob_it.data ();        if (gblob_bounding_box (blob, polyg).overlap (selection_box)) {          if (new_word == NULL) {            new_word = word->shallow_copy ();            new_blob_it.set_to_list (new_word->gblob_list ());          }          new_blob_it.add_to_end (blob_it.extract ());          //move blob        }      }      if (blob_it.empty ()) {    //no blobs in word                                 //so delete word        delete word_it.extract ();      }    }  }  if (new_word != NULL) {    gblob_sort_list (new_word->gblob_list (), polyg);    word_it.add_to_end (new_word);    word_it.sort (word_comparator);    row_to_process->bounding_box ().plot (image_win,      INT_SOLID, FALSE, BLACK, BLACK);    word_it.set_to_list (row_to_process->word_list ());    for (word_it.mark_cycle_pt ();      !word_it.cycled_list (); word_it.forward ())    word_display (block_to_process, row_to_process, word_it.data ());    *current_image_changed = TRUE;  }}void block_space_stat(                         //show space stats                      BLOCK_LIST *block_list,  //blocks to check                      BOX &selection_box) {  BLOCK_IT block_it(block_list);  BLOCK *block;  ROW_IT row_it;  ROW *row;  int block_idx = 0;  STATS all_gap_stats (0, MAXSPACING);  WERD_IT word_it;  WERD *word;  PBLOB_IT blob_it;  PBLOB *blob;  C_BLOB_IT cblob_it;  C_BLOB *cblob;  BOX box;  INT16 prev_box_right;  INT16 gap_width;  INT16 min_inter_word_gap;  INT16 max_inter_char_gap;  /* Find blocks to process */  for (block_it.mark_cycle_pt ();  !block_it.cycled_list (); block_it.forward ()) {    block_idx++;    block = block_it.data ();    if (block->bounding_box ().overlap (selection_box)) {      /* Process a block */      tprintf ("\nBlock %d\n", block_idx);      min_inter_word_gap = 3000;      max_inter_char_gap = 0;      all_gap_stats.clear ();      row_it.set_to_list (block->row_list ());      for (row_it.mark_cycle_pt ();      !row_it.cycled_list (); row_it.forward ()) {        row = row_it.data ();        prev_box_right = -1;        word_it.set_to_list (row->word_list ());        for (word_it.mark_cycle_pt ();        !word_it.cycled_list (); word_it.forward ()) {          word = word_it.data ();          if (word->flag (W_POLYGON)) {            blob_it.set_to_list (word->blob_list ());            for (blob_it.mark_cycle_pt ();            !blob_it.cycled_list (); blob_it.forward ()) {              blob = blob_it.data ();              box = blob->bounding_box ();              if (prev_box_right > -1) {                gap_width = box.left () - prev_box_right;                all_gap_stats.add (gap_width, 1);                if (blob_it.at_first ()) {                  if (gap_width < min_inter_word_gap)                    min_inter_word_gap = gap_width;                }                else {                  if (gap_width > max_inter_char_gap)                    max_inter_char_gap = gap_width;                }              }              prev_box_right = box.right ();            }          }          else {            cblob_it.set_to_list (word->cblob_list ());            for (cblob_it.mark_cycle_pt ();            !cblob_it.cycled_list (); cblob_it.forward ()) {              cblob = cblob_it.data ();              box = cblob->bounding_box ();              if (prev_box_right > -1) {                gap_width = box.left () - prev_box_right;                all_gap_stats.add (gap_width, 1);                if (cblob_it.at_first ()) {                  if (gap_width < min_inter_word_gap)                    min_inter_word_gap = gap_width;                }                else {                  if (gap_width > max_inter_char_gap)                    max_inter_char_gap = gap_width;                }              }              prev_box_right = box.right ();            }          }        }      }      tprintf ("Max inter char gap = %d.\nMin inter word gap = %d.\n",        max_inter_char_gap, min_inter_word_gap);      all_gap_stats.short_print (NULL, TRUE);      all_gap_stats.smooth (2);      tprintf ("SMOOTHED DATA...\n");      all_gap_stats.short_print (NULL, TRUE);    }  }}void row_space_stat(                         //show space stats                    BLOCK_LIST *block_list,  //blocks to check                    BOX &selection_box) {  BLOCK_IT block_it(block_list);  BLOCK *block;  ROW_IT row_it;  ROW *row;  int block_idx = 0;  int row_idx;  STATS all_gap_stats (0, MAXSPACING);  WERD_IT word_it;  WERD *word;  PBLOB_IT blob_it;  PBLOB *blob;  C_BLOB_IT cblob_it;  C_BLOB *cblob;  BOX box;  INT16 prev_box_right;  INT16 gap_width;  INT16 min_inter_word_gap;  INT16 max_inter_char_gap;  /* Find rows to process */  for (block_it.mark_cycle_pt ();  !block_it.cycled_list (); block_it.forward ()) {    block_idx++;    block = block_it.data ();    if (block->bounding_box ().overlap (selection_box)) {      row_it.set_to_list (block->row_list ());      row_idx = 0;      for (row_it.mark_cycle_pt ();      !row_it.cycled_list (); row_it.forward ()) {        row_idx++;        row = row_it.data ();        if (row->bounding_box ().overlap (selection_box)) {          /* Process a row */          tprintf ("\nBlock %d Row %d\n", block_idx, row_idx);          min_inter_word_gap = 3000;          max_inter_char_gap = 0;          prev_box_right = -1;          all_gap_stats.clear ();          word_it.set_to_list (row->word_list ());          for (word_it.mark_cycle_pt ();          !word_it.cycled_list (); word_it.forward ()) {            word = word_it.data ();            if (word->flag (W_POLYGON)) {              blob_it.set_to_list (word->blob_list ());              for (blob_it.mark_cycle_pt ();              !blob_it.cycled_list (); blob_it.forward ()) {                blob = blob_it.data ();                box = blob->bounding_box ();                if (prev_box_right > -1) {                  gap_width = box.left () - prev_box_right;                  all_gap_stats.add (gap_width, 1);                  if (blob_it.at_first ()) {                    if (gap_width < min_inter_word_gap)                      min_inter_word_gap = gap_width;                  }                  else {                    if (gap_width > max_inter_char_gap)                      max_inter_char_gap = gap_width;                  }                }                prev_box_right = box.right ();              }            }            else {              cblob_it.set_to_list (word->cblob_list ());              for (cblob_it.mark_cycle_pt ();              !cblob_it.cycled_list (); cblob_it.forward ()) {                cblob = cblob_it.data ();                box = cblob->bounding_box ();                if (prev_box_right > -1) {                  gap_width = box.left () - prev_box_right;                  all_gap_stats.add (gap_width, 1);                  if (cblob_it.at_first ()) {                    if (gap_width < min_inter_word_gap)                      min_inter_word_gap = gap_width;                  }                  else {                    if (gap_width > max_inter_char_gap)                      max_inter_char_gap = gap_width;                  }                }                prev_box_right = box.right ();              }            }          }          tprintf            ("Max inter char gap = %d.\nMin inter word gap = %d.\n",            max_inter_char_gap, min_inter_word_gap);          all_gap_stats.short_print (NULL, TRUE);          all_gap_stats.smooth (2);          tprintf ("SMOOTHED DATA...\n");          all_gap_stats.short_print (NULL, TRUE);        }      }    }  }}/********************************************************************** * show_point() * * Show coords of point, blob bounding box, word bounding box and offset from * row baseline **********************************************************************/void show_point(                         //display posn of bloba word                BLOCK_LIST *block_list,  //blocks to check                float x,                float y) {  FCOORD pt(x, y);  BOX box;  BLOCK_IT block_it(block_list);  BLOCK *block;  ROW_IT row_it;  ROW *row;  WERD_IT word_it;  WERD *word;  PBLOB_IT blob_it;  PBLOB *blob;  C_BLOB_IT cblob_it;  C_BLOB *cblob;  char msg[160];  char *msg_ptr = msg;  msg_ptr += sprintf (msg_ptr, "Pt:(%0.3f, %0.3f) ", x, y);  for (block_it.mark_cycle_pt ();  !block_it.cycled_list (); block_it.forward ()) {    block = block_it.data ();    if (block->bounding_box ().contains (pt)) {      row_it.set_to_list (block->row_list ());      for (row_it.mark_cycle_pt ();      !row_it.cycled_list (); row_it.forward ()) {        row = row_it.data ();        if (row->bounding_box ().contains (pt)) {          msg_ptr += sprintf (msg_ptr, "BL(x)=%0.3f ",            row->base_line (x));          word_it.set_to_list (row->word_list ());          for (word_it.mark_cycle_pt ();          !word_it.cycled_list (); word_it.forward ()) {            word = word_it.data ();            box = word->bounding_box ();            if (box.contains (pt)) {              msg_ptr += sprintf (msg_ptr,                "Wd(%d, %d)/(%d, %d) ",                box.left (), box.bottom (),                box.right (), box.top ());              if (word->flag (W_POLYGON)) {                blob_it.set_to_list (word->blob_list ());                for (blob_it.mark_cycle_pt ();                  !blob_it.cycled_list ();                blob_it.forward ()) {                  blob = blob_it.data ();                  box = blob->bounding_box ();                  if (box.contains (pt)) {                    msg_ptr += sprintf (msg_ptr,                      "Blb(%d, %d)/(%d, %d) ",                      box.left (),                      box.bottom (),                      box.right (),                      box.top ());                  }                }              }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -