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

📄 tospace.cpp

📁 一OCR的相关资料。.希望对研究OCR的朋友有所帮助.
💻 CPP
📖 第 1 页 / 共 5 页
字号:
          make_a_word_break (row, blob_box, prev_gap, prev_blob_box,          current_gap, current_within_xht_gap,          next_blob_box, next_gap,          blanks, fuzzy_sp, fuzzy_non)) ||          (tosp_only_use_xht_gaps &&          make_a_word_break (row, blob_box, prev_within_xht_gap,          prev_blob_box,          current_gap, current_within_xht_gap,          next_blob_box, next_within_xht_gap,          blanks, fuzzy_sp, fuzzy_non)) ||        box_it.at_first ()) {          /* Form a new word out of the blobs collected */          if (!blob_it.empty ()) {            word = new WERD (&blobs, prev_blanks, NULL);            //make real word            word_count++;          }          else {            word = new WERD (&cblobs, prev_blanks, NULL);            word_count++;          }          word_it.add_after_then_move (word);          if (bol) {            word->set_flag (W_BOL, TRUE);            bol = FALSE;          }          if (prev_fuzzy_sp)                                 //probably space            word->set_flag (W_FUZZY_SP, TRUE);          else if (prev_fuzzy_non)            word->set_flag (W_FUZZY_NON, TRUE);          //probably not          if (blob_box.left () > next_rep_char_word_right) {            /* We need to insert a repeated char word */            word = rep_char_it.extract ();            word_it.add_after_then_move (word);            /* Set spaces before repeated char word */            repetition_spacing = find_mean_blob_spacing (word);            current_gap = word->bounding_box ().left () - prev_x;            current_within_xht_gap = current_gap;            if (current_gap > tosp_rep_space * repetition_spacing) {              blanks =                (UINT8) floor (current_gap / row->space_size);              if (blanks < 1)                blanks = 1;            }            else              blanks = 0;            if (tosp_debug_level > 5)              tprintf                ("Repch wd (%d,%d) rep gap %5.2f;  Lgap:%d (%d blanks);",                word->bounding_box ().left (),                word->bounding_box ().bottom (),                repetition_spacing, current_gap, blanks);            word->set_blanks (blanks);                                 //NO uncertainty            word->set_flag (W_FUZZY_SP, FALSE);            word->set_flag (W_FUZZY_NON, FALSE);            /* Set spaces after repeated char word (and leave current word set) */            current_gap =              blob_box.left () - next_rep_char_word_right;            if (current_gap > tosp_rep_space * repetition_spacing) {              blanks = (UINT8) (current_gap / row->space_size);              if (blanks < 1)                blanks = 1;            }            else              blanks = 0;            if (tosp_debug_level > 5)              tprintf (" Rgap:%d (%d blanks)\n",                current_gap, blanks);            fuzzy_sp = FALSE;            fuzzy_non = FALSE;            if (rep_char_it.empty ()) {              next_rep_char_word_right = MAX_INT32;            }            else {              rep_char_it.forward ();              next_rep_char_word_right =                rep_char_it.data ()->bounding_box ().right ();            }          }          if (box_it.at_first () && rep_char_it.empty ()) {                                 //at end of line            word->set_flag (W_EOL, TRUE);            xstarts[1] = prev_x;          }          else {            prev_blanks = blanks;            prev_fuzzy_sp = fuzzy_sp;            prev_fuzzy_non = fuzzy_non;          }        }      }    }    while (!box_it.at_first ()); //until back at start    /* Insert any further repeated char words */    while (!rep_char_it.empty ()) {      word = rep_char_it.extract ();      word_it.add_after_then_move (word);      /* Set spaces before repeated char word */      repetition_spacing = find_mean_blob_spacing (word);      current_gap = word->bounding_box ().left () - prev_x;      if (current_gap > tosp_rep_space * repetition_spacing) {        blanks = (UINT8) floor (current_gap / row->space_size);        if (blanks < 1)          blanks = 1;      }      else        blanks = 0;      if (tosp_debug_level > 5)        tprintf          ("Repch wd at EOL (%d,%d). rep spacing %d; Lgap:%d (%d blanks)\n",          word->bounding_box ().left (), word->bounding_box ().bottom (),          repetition_spacing, current_gap, blanks);      word->set_blanks (blanks);                                 //NO uncertainty      word->set_flag (W_FUZZY_SP, FALSE);      word->set_flag (W_FUZZY_NON, FALSE);      prev_x = word->bounding_box ().right ();      if (rep_char_it.empty ()) {                                 //at end of line        word->set_flag (W_EOL, TRUE);        xstarts[1] = prev_x;      }      else {        rep_char_it.forward ();      }    }    coeffs[0] = 0;    coeffs[1] = row->line_m ();    coeffs[2] = row->line_c ();    real_row = new ROW (row,      (INT16) row->kern_size, (INT16) row->space_size);    word_it.set_to_list (real_row->word_list ());                                 //put words in row    word_it.add_list_after (&words);    real_row->recalc_bounding_box ();    if (tosp_debug_level > 9) {      tprintf ("Row %d Made %d words in row ((%d,%d)(%d,%d))\n",        row_count,        word_count,        real_row->bounding_box ().left (),        real_row->bounding_box ().bottom (),        real_row->bounding_box ().right (),        real_row->bounding_box ().top ());    }    return real_row;  }  return NULL;}BOOL8 make_a_word_break(               //decide on word break                        TO_ROW *row,   //row being made                        BOX blob_box,  //for next_blob //how many blanks?                        INT16 prev_gap,                        BOX prev_blob_box,                        INT16 real_current_gap,                        INT16 within_xht_current_gap,                        BOX next_blob_box,                        INT16 next_gap,                        UINT8 &blanks,                        BOOL8 &fuzzy_sp,                        BOOL8 &fuzzy_non) {  static BOOL8 prev_gap_was_a_space;  BOOL8 space;  INT16 current_gap;  float fuzzy_sp_to_kn_limit;  /* Inhibit using the reduced gap if    The kerning is large - chars are not kerned and reducing "f"s can cause    erroneous blanks  OR  The real gap is less than 0  OR  The real gap is less than the kerning estimate  */  if ((row->kern_size > tosp_large_kerning * row->xheight) ||    ((tosp_dont_fool_with_small_kerns >= 0) &&    (real_current_gap < tosp_dont_fool_with_small_kerns * row->kern_size)))                                 //Ignore the difference    within_xht_current_gap = real_current_gap;  if (tosp_use_xht_gaps && tosp_only_use_xht_gaps)    current_gap = within_xht_current_gap;  else    current_gap = real_current_gap;  if (tosp_old_to_method) {                                 //Boring old method    space = current_gap > row->max_nonspace;    if (space && (current_gap < MAX_INT16)) {      if (current_gap < row->min_space) {        if (current_gap > row->space_threshold) {          blanks = 1;          fuzzy_sp = TRUE;          fuzzy_non = FALSE;        }        else {          blanks = 0;          fuzzy_sp = FALSE;          fuzzy_non = TRUE;        }      }      else {        blanks = (UINT8) (current_gap / row->space_size);        if (blanks < 1)          blanks = 1;        fuzzy_sp = FALSE;        fuzzy_non = FALSE;      }    }    return space;  }  else {  /* New exciting heuristic method */    if (prev_blob_box.null_box ())                                 //Beginning of row        prev_gap_was_a_space = TRUE;                                 //Default as old TO    space = current_gap > row->space_threshold;    /* Set defaults for the word break incase we find one.  Currently there are    no fuzzy spaces. Depending on the reliability of the different heuristics    we may need to set PARTICULAR spaces to fuzzy or not. The values will ONLY    be used if the function returns TRUE - ie the word is to be broken.    */    blanks = (UINT8) (current_gap / row->space_size);    if (blanks < 1)      blanks = 1;    fuzzy_sp = FALSE;    fuzzy_non = FALSE;    /*    If xht measure causes gap to flip one of the 3 thresholds act accordingly -    despite any other heuristics - the MINIMUM action is to pass a fuzzy kern to    context.    */    if (tosp_use_xht_gaps &&      (real_current_gap <= row->max_nonspace) &&    (within_xht_current_gap > row->max_nonspace)) {      space = TRUE;      fuzzy_non = TRUE;#ifndef GRAPHICS_DISABLED      mark_gap (blob_box, 20,        prev_gap, prev_blob_box.width (),        current_gap, next_blob_box.width (), next_gap);#endif    }    else if (tosp_use_xht_gaps &&      (real_current_gap <= row->space_threshold) &&    (within_xht_current_gap > row->space_threshold)) {      space = TRUE;      if (tosp_flip_fuzz_kn_to_sp)        fuzzy_sp = TRUE;      else        fuzzy_non = TRUE;#ifndef GRAPHICS_DISABLED      mark_gap (blob_box, 21,        prev_gap, prev_blob_box.width (),        current_gap, next_blob_box.width (), next_gap);#endif    }    else if (tosp_use_xht_gaps &&      (real_current_gap < row->min_space) &&    (within_xht_current_gap >= row->min_space)) {      space = TRUE;#ifndef GRAPHICS_DISABLED      mark_gap (blob_box, 22,        prev_gap, prev_blob_box.width (),        current_gap, next_blob_box.width (), next_gap);#endif    }    /* Now continue with normal heuristics */    else if ((current_gap < row->min_space) &&    (current_gap > row->space_threshold)) {      /* Heuristics to turn dubious spaces to kerns */      if (tosp_pass_wide_fuzz_sp_to_context > 0)        fuzzy_sp_to_kn_limit = row->kern_size +          tosp_pass_wide_fuzz_sp_to_context *          (row->space_size - row->kern_size);      else        fuzzy_sp_to_kn_limit = 99999.0f;      /* If current gap is significantly smaller than the previous space the other      side of a narrow blob then this gap is a kern. */      if ((prev_blob_box.width () > 0) &&        narrow_blob (row, prev_blob_box) &&        prev_gap_was_a_space &&      (current_gap <= tosp_gap_factor * prev_gap)) {        if ((tosp_all_flips_fuzzy) ||        (current_gap > fuzzy_sp_to_kn_limit)) {          if (tosp_flip_fuzz_sp_to_kn)            fuzzy_non = TRUE;          else            fuzzy_sp = TRUE;        }        else          space = FALSE;#ifndef GRAPHICS_DISABLED        mark_gap (blob_box, 1,          prev_gap, prev_blob_box.width (),          current_gap, next_blob_box.width (), next_gap);#endif      }      /* If current gap not much bigger than the previous kern the other side of a      narrow blob then this gap is a kern as well */      else if ((prev_blob_box.width () > 0) &&        narrow_blob (row, prev_blob_box) &&        !prev_gap_was_a_space &&      (current_gap * tosp_gap_factor <= prev_gap)) {        if ((tosp_all_flips_fuzzy) ||        (current_gap > fuzzy_sp_to_kn_limit)) {          if (tosp_flip_fuzz_sp_to_kn)            fuzzy_non = TRUE;          else            fuzzy_sp = TRUE;        }        else          space = FALSE;#ifndef GRAPHICS_DISABLED        mark_gap (blob_box, 2,          prev_gap, prev_blob_box.width (),          current_gap, next_blob_box.width (), next_gap);#endif      }      else if ((next_blob_box.width () > 0) &&        narrow_blob (row, next_blob_box) &&        (next_gap > row->space_threshold) &&      (current_gap <= tosp_gap_factor * next_gap)) {        if ((tosp_all_flips_fuzzy) ||        (current_gap > fuzzy_sp_to_kn_limit)) {          if (tosp_flip_fuzz_sp_to_kn)            fuzzy_non = TRUE;          else            fuzzy_sp = TRUE;        }        else          space = FALSE;#ifndef GRAPHICS_DISABLED        mark_gap (blob_box, 3,          prev_gap, prev_blob_box.width (),          current_gap, next_blob_box.width (), next_gap);#endif      }      else if ((next_blob_box.width () > 0) &&        narrow_blob (row, next_blob_box) &&        (next_gap <= row->space_threshold) &&      (current_gap * tosp_gap_factor <= next_gap)) {        if ((tosp_all_flips_fuzzy) ||        (current_gap > fuzzy_sp_to_kn_limit)) {          if (tosp_flip_fuzz_sp_to_kn)            fuzzy_non = TRUE;          else            fuzzy_sp = TRUE;        }

⌨️ 快捷键说明

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