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

📄 fpchop.cpp

📁 一OCR的相关资料。.希望对研究OCR的朋友有所帮助.
💻 CPP
📖 第 1 页 / 共 4 页
字号:
  }  else {    master_it.set_to_list (&bottom->polypts);    ASSERT_HOST (top->polypts.empty ());    slave_it.set_to_list (&top->other_end->polypts);    cutpt = slave_it.data_relative (-1);    nextpt = master_it.data ();    if (bottom->other_end != top)      master_it.add_list_before (&top->other_end->polypts);  }  cutpt->vec = nextpt->pos - cutpt->pos;}/********************************************************************** * fixed_chop_cblob * * Chop the given cblob (if any) and the existing right outlines to * produce a list of outlines left of the chop point and more to the right. **********************************************************************/void fixed_chop_cblob(                                //split the blob                      C_BLOB *blob,                   //blob to split                      INT16 chop_coord,               //place to chop                      float pitch_error,              //allowed deviation                      C_OUTLINE_LIST *left_outlines,  //left half of chop                      C_OUTLINE_LIST *right_outlines  //right half of chop                     ) {  C_OUTLINE *old_right;          //already there  C_OUTLINE_LIST new_outlines;   //new right ones                                 //ouput iterator  C_OUTLINE_IT left_it = left_outlines;                                 //in/out iterator  C_OUTLINE_IT right_it = right_outlines;  C_OUTLINE_IT new_it = &new_outlines;  C_OUTLINE_IT blob_it;          //outlines in blob  if (!right_it.empty ()) {    while (!right_it.empty ()) {      old_right = right_it.extract ();      right_it.forward ();      fixed_split_coutline(old_right,                           chop_coord,                           pitch_error,                           &left_it,                           &new_it);    }    right_it.add_list_before (&new_outlines);  }  if (blob != NULL) {    blob_it.set_to_list (blob->out_list ());    for (blob_it.mark_cycle_pt (); !blob_it.cycled_list ();      blob_it.forward ())    fixed_split_coutline (blob_it.extract (), chop_coord, pitch_error,        &left_it, &right_it);    delete blob;  }}/********************************************************************** * fixed_split_outline * * Chop the given outline (if necessary) placing the fragments which * fall either side of the chop line into the appropriate list. **********************************************************************/void fixed_split_coutline(                        //chop the outline                          C_OUTLINE *srcline,     //source outline                          INT16 chop_coord,       //place to chop                          float pitch_error,      //allowed deviation                          C_OUTLINE_IT *left_it,  //left half of chop                          C_OUTLINE_IT *right_it  //right half of chop                         ) {  C_OUTLINE *child;              //child outline  BOX srcbox;                    //box of outline  C_OUTLINE_LIST left_ch;        //left children  C_OUTLINE_LIST right_ch;       //right children  C_OUTLINE_FRAG_LIST left_frags;//chopped fragments  C_OUTLINE_FRAG_LIST right_frags;;  C_OUTLINE_IT left_ch_it = &left_ch;                                 //for whole children  C_OUTLINE_IT right_ch_it = &right_ch;                                 //for holes  C_OUTLINE_IT child_it = srcline->child ();  srcbox = srcline->bounding_box ();                                 //left of line  if (srcbox.left () + srcbox.right () <= chop_coord * 2                                 //and not far over    && srcbox.right () < chop_coord + pitch_error)                                 //stick whole in left    left_it->add_after_then_move (srcline);  else if (srcbox.left () + srcbox.right () > chop_coord * 2    && srcbox.left () > chop_coord - pitch_error)                                 //stick whole in right    right_it->add_before_stay_put (srcline);  else {                                 //needs real chopping    if (fixed_chop_coutline (srcline, chop_coord, pitch_error,    &left_frags, &right_frags)) {      for (child_it.mark_cycle_pt (); !child_it.cycled_list ();      child_it.forward ()) {        child = child_it.extract ();        srcbox = child->bounding_box ();        if (srcbox.right () < chop_coord)          left_ch_it.add_after_then_move (child);        else if (srcbox.left () > chop_coord)          right_ch_it.add_after_then_move (child);        else {          if (fixed_chop_coutline (child, chop_coord, pitch_error,            &left_frags, &right_frags))            delete child;          else {            if (srcbox.left () + srcbox.right () <= chop_coord * 2)              left_ch_it.add_after_then_move (child);            else              right_ch_it.add_after_then_move (child);          }        }      }      close_chopped_cfragments(&left_frags, &left_ch, pitch_error, left_it);       close_chopped_cfragments(&right_frags, &right_ch, pitch_error, right_it);       ASSERT_HOST (left_ch.empty () && right_ch.empty ());      //no children left      delete srcline;            //smashed up    }    else {      if (srcbox.left () + srcbox.right () <= chop_coord * 2)                                 //stick whole in left        left_it->add_after_then_move (srcline);      else        right_it->add_before_stay_put (srcline);    }  }}/********************************************************************** * fixed_chop_coutline * * Chop the given coutline (if necessary) placing the fragments which * fall either side of the chop line into the appropriate list. * If the coutline lies too heavily to one side to chop, FALSE is returned. **********************************************************************/BOOL8 fixed_chop_coutline(                                  //chop the outline                          C_OUTLINE *srcline,               //source outline                          INT16 chop_coord,                 //place to chop                          float pitch_error,                //allowed deviation                          C_OUTLINE_FRAG_LIST *left_frags,  //left half of chop                          C_OUTLINE_FRAG_LIST *right_frags  //right half of chop                         ) {  BOOL8 first_frag;              //fragment  BOOL8 anticlock;               //direction of loop  INT16 left_edge;               //of outline  INT16 startindex;              //in first fragment  INT32 length;                  //of outline  INT16 stepindex;               //into outline  INT16 head_index;              //start of fragment  ICOORD head_pos;               //start of fragment  INT16 tail_index;              //end of fragment  ICOORD tail_pos;               //end of fragment  ICOORD pos;                    //current point  INT16 first_index = 0;         //first tail  ICOORD first_pos;              //first tail  length = srcline->pathlength ();  pos = srcline->start_pos ();  anticlock = srcline->turn_direction () > 0;  left_edge = pos.x ();  tail_index = 0;  tail_pos = pos;  for (stepindex = 0; stepindex < length; stepindex++) {    if (pos.x () < left_edge) {      left_edge = pos.x ();      tail_index = stepindex;      tail_pos = pos;    }    pos += srcline->step (stepindex);  }  if (left_edge >= chop_coord - pitch_error)    return FALSE;                //not worth it  startindex = tail_index;  first_frag = TRUE;  head_index = tail_index;  head_pos = tail_pos;  do {    do {      tail_pos += srcline->step (tail_index);      tail_index++;      if (tail_index == length)        tail_index = 0;    }    while (tail_pos.x () != chop_coord && tail_index != startindex);    if (tail_index == startindex) {      if (first_frag)        return FALSE;            //doesn't cross line      else        break;    }    //#ifdef __UNIX__    ASSERT_HOST (head_index != tail_index);    //#endif    if (!first_frag) {      save_chop_cfragment(head_index,                          head_pos,                          tail_index,                          tail_pos,                          srcline,                          left_frags);    }    else {      first_index = tail_index;      first_pos = tail_pos;      first_frag = FALSE;    }    while (srcline->step (tail_index).x () == 0) {      tail_pos += srcline->step (tail_index);      tail_index++;      if (tail_index == length)        tail_index = 0;    }    head_index = tail_index;    head_pos = tail_pos;    while (srcline->step (tail_index).x () > 0) {      do {        tail_pos += srcline->step (tail_index);        tail_index++;        if (tail_index == length)          tail_index = 0;      }      while (tail_pos.x () != chop_coord);      //#ifdef __UNIX__      ASSERT_HOST (head_index != tail_index);      //#endif      save_chop_cfragment(head_index,                          head_pos,                          tail_index,                          tail_pos,                          srcline,                          right_frags);      while (srcline->step (tail_index).x () == 0) {        tail_pos += srcline->step (tail_index);        tail_index++;        if (tail_index == length)          tail_index = 0;      }      head_index = tail_index;      head_pos = tail_pos;    }  }  while (tail_index != startindex);  save_chop_cfragment(head_index,                      head_pos,                      first_index,                      first_pos,                      srcline,                      left_frags);  return TRUE;                   //did some chopping}/********************************************************************** * next_anti_left_seg * * Search the outline for a suitable point at which it crosses the * chop_coord from left to right. **********************************************************************/INT16 next_anti_left_seg(                     //chop the outline                         C_OUTLINE *srcline,  //source outline                         INT16 tail_index,    //of tailpos                         INT16 startindex,    //end of search                         INT32 length,        //of outline                         INT16 chop_coord,    //place to chop                         float pitch_error,   //allowed deviation                         ICOORD *tail_pos     //current position                        ) {  BOOL8 test_valid;              //test pt valid  INT16 chop_starty;             //test chop pt  INT16 test_index;              //possible chop pt  ICOORD test_pos;               //possible chop pt  ICOORD prev_step;              //in x to tail pos  test_valid = FALSE;  chop_starty = -MAX_INT16;  test_index = tail_index;       //stop warnings  do {    *tail_pos += srcline->step (tail_index);    prev_step = srcline->step (tail_index);    tail_index++;    if (tail_index >= length)      tail_index = 0;    if (test_valid && tail_pos->x () == chop_coord && prev_step.x () < 0) {      if (tail_pos->y () >= chop_starty) {        chop_starty = -MAX_INT16;        test_valid = FALSE;      }      else {        *tail_pos = test_pos;        tail_index = test_index;        break;                   //must chop there      }    }    if (tail_pos->x () == chop_coord      && srcline->step (tail_index).x () > 0    && tail_pos->y () > chop_starty) {      chop_starty = tail_pos->y ();      test_index = tail_index;      test_pos = *tail_pos;      test_valid = TRUE;    }    else if (tail_pos->x () == chop_coord      && srcline->step (tail_index).y () < 0      && prev_step.x () > 0 && tail_pos->y () > chop_starty)      break;                     //must chop here  }  while (tail_index != startindex    && tail_pos->x () < chop_coord + pitch_error);  return tail_index;}/********************************************************************** * next_anti_right_seg * * Search the outline for a suitable point at which it crosses the * chop_coord from right to left. **********************************************************************/INT16 next_anti_right_seg(                     //chop the outline                          C_OUTLINE *srcline,  //source outline                          INT16 tail_index,    //of tailpos                          INT16 startindex,    //end of search                          INT32 length,        //of outline                          INT16 chop_coord,    //place to chop                          float pitch_error,   //allowed deviation                          ICOORD *tail_pos     //current position                         ) {  BOOL8 test_valid;              //test pt valid  INT16 chop_starty;             //test chop pt  INT16 test_index;              //possible chop pt  ICOORD test_pos;               //possible chop pt  ICOORD prev_step;              //in x to tail pos  test_valid = FALSE;  chop_starty = MAX_INT16;  test_index = tail_index;       //stop warnings  do {                                 //move forward    *tail_pos += srcline->step (tail_index);    prev_step = srcline->step (tail_index);    tail_index++;    if (tail_index >= length)      tail_index = 0;    if (test_valid && tail_pos->x () == chop_coord && prev_step.x () > 0) {      if (tail_pos->y () <= chop_starty) {        chop_starty = MAX_INT16;        test_valid = FALSE;      }      else {        *tail_pos = test_pos;        tail_index = test_index;        break;                   //must chop there      }    }    if (tail_pos->x () == chop_coord      && srcline->step (tail_index).x () < 0    && tail_pos->y () < chop_starty) {      chop_starty = tail_pos->y ();      test_index = tail_index;      test_pos = *tail_pos;      test_valid = TRUE;         //save possible chop pt    }    else if (tail_pos->x () == chop_coord      && srcline->step (tail_index).y () > 0      && prev_step.x () < 0 && tail_pos->y () < chop_starty)      break;                     //must chop here  }  while (tail_index != startindex    && tail_pos->x () > chop_coord - pitch_error);  return tail_index;}/********************************************************************** * next_clock_left_seg * * Search the outline for a suitable point at which it crosses the * chop_coord from left to right. **********************************************************************/INT16 next_clock_left_seg(                     //chop the outline                          C_OUTLINE *srcline,  //source outline                          INT16 tail_index,    //of tailpos                          INT16 startindex,    //end of search                          INT32 length,        //of outline                          INT16 chop_coord,    //place to chop                          float pitch_error,   //allowed deviation                          ICOORD *tail_pos     //current position                         ) {  BOOL8 test_valid;              //test pt valid  INT16 chop_starty;             //test chop pt  INT16 test_index;              //possible chop pt  ICOORD test_pos;               //possible chop pt  ICOORD prev_step;              //in x to tail pos  test_valid = FALSE;  chop_starty = MAX_INT16;

⌨️ 快捷键说明

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