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

📄 coutln.cpp

📁 一OCR的相关资料。.希望对研究OCR的朋友有所帮助.
💻 CPP
📖 第 1 页 / 共 2 页
字号:
  looking_for_max_y = TRUE;  looking_for_min_y = TRUE;  first_was_max_x = FALSE;  first_was_max_y = FALSE;  initial_x = pos.x ();  initial_y = pos.y ();          //stop uninit warning  for (stepindex = 0; stepindex < total_steps; stepindex++) {                                 //all intersected    next_step = step (stepindex);    pos += next_step;    if (next_step.x () < 0) {      if (looking_for_max_x && pos.x () < min_x)        min_x = pos.x ();      if (looking_for_min_x && max_x - pos.x () > threshold) {        if (looking_for_max_x) {          initial_x = max_x;          first_was_max_x = FALSE;        }        total++;        looking_for_max_x = TRUE;        looking_for_min_x = FALSE;        min_x = pos.x ();        //reset min      }    }    else if (next_step.x () > 0) {      if (looking_for_min_x && pos.x () > max_x)        max_x = pos.x ();      if (looking_for_max_x && pos.x () - min_x > threshold) {        if (looking_for_min_x) {          initial_x = min_x;     //remember first min          first_was_max_x = TRUE;        }        total++;        looking_for_max_x = FALSE;        looking_for_min_x = TRUE;        max_x = pos.x ();      }    }    else if (next_step.y () < 0) {      if (looking_for_max_y && pos.y () < min_y)        min_y = pos.y ();      if (looking_for_min_y && max_y - pos.y () > threshold) {        if (looking_for_max_y) {          initial_y = max_y;     //remember first max          first_was_max_y = FALSE;        }        total++;        looking_for_max_y = TRUE;        looking_for_min_y = FALSE;        min_y = pos.y ();        //reset min      }    }    else {      if (looking_for_min_y && pos.y () > max_y)        max_y = pos.y ();      if (looking_for_max_y && pos.y () - min_y > threshold) {        if (looking_for_min_y) {          initial_y = min_y;     //remember first min          first_was_max_y = TRUE;        }        total++;        looking_for_max_y = FALSE;        looking_for_min_y = TRUE;        max_y = pos.y ();      }    }  }  if (first_was_max_x && looking_for_min_x) {    if (max_x - initial_x > threshold)      total++;    else      total--;  }  else if (!first_was_max_x && looking_for_max_x) {    if (initial_x - min_x > threshold)      total++;    else      total--;  }  if (first_was_max_y && looking_for_min_y) {    if (max_y - initial_y > threshold)      total++;    else      total--;  }  else if (!first_was_max_y && looking_for_max_y) {    if (initial_y - min_y > threshold)      total++;    else      total--;  }  return total;}/********************************************************************** * C_OUTLINE::operator< * * Return TRUE if the left operand is inside the right one. **********************************************************************/BOOL8C_OUTLINE::operator< (           //winding numberconst C_OUTLINE & other          //other outline) const{  INT16 count = 0;               //winding count  ICOORD pos;                    //position of point  INT32 stepindex;               //index to cstep  if (!box.overlap (other.box))    return FALSE;                //can't be contained  pos = start;  for (stepindex = 0; stepindex < stepcount    && (count = other.winding_number (pos)) == INTERSECTING; stepindex++)    pos += step (stepindex);     //try all points  if (count == INTERSECTING) {                                 //all intersected    pos = other.start;    for (stepindex = 0; stepindex < other.stepcount      && (count = winding_number (pos)) == INTERSECTING; stepindex++)                                 //try other way round      pos += other.step (stepindex);    return count == INTERSECTING || count == 0;  }  return count != 0;}/********************************************************************** * C_OUTLINE::winding_number * * Return the winding number of the outline around the given point. **********************************************************************/INT16 C_OUTLINE::winding_number(              //winding number                                ICOORD point  //point to wind around                               ) const {  INT16 stepindex;               //index to cstep  INT16 count;                   //winding count  ICOORD vec;                    //to current point  ICOORD stepvec;                //step vector  INT32 cross;                   //cross product  vec = start - point;           //vector to it  count = 0;  for (stepindex = 0; stepindex < stepcount; stepindex++) {    stepvec = step (stepindex);  //get the step                                 //crossing the line    if (vec.y () <= 0 && vec.y () + stepvec.y () > 0) {      cross = vec * stepvec;     //cross product      if (cross > 0)        count++;                 //crossing right half      else if (cross == 0)        return INTERSECTING;     //going through point    }    else if (vec.y () > 0 && vec.y () + stepvec.y () <= 0) {      cross = vec * stepvec;      if (cross < 0)        count--;                 //crossing back      else if (cross == 0)        return INTERSECTING;     //illegal    }    vec += stepvec;              //sum vectors  }  return count;                  //winding number}/********************************************************************** * C_OUTLINE::turn_direction * * Return the sum direction delta of the outline. **********************************************************************/INT16 C_OUTLINE::turn_direction() const {  //winding number  DIR128 prevdir;                //previous direction  DIR128 dir;                    //current direction  INT16 stepindex;               //index to cstep  INT8 dirdiff;                  //direction difference  INT16 count;                   //winding count  count = 0;  prevdir = step_dir (stepcount - 1);  for (stepindex = 0; stepindex < stepcount; stepindex++) {    dir = step_dir (stepindex);    dirdiff = dir - prevdir;    ASSERT_HOST (dirdiff == 0 || dirdiff == 32 || dirdiff == -32);    count += dirdiff;    prevdir = dir;  }  ASSERT_HOST (count == 128 || count == -128);  return count;                  //winding number}/********************************************************************** * C_OUTLINE::reverse * * Reverse the direction of an outline. **********************************************************************/void C_OUTLINE::reverse() {  //reverse drection  DIR128 halfturn = MODULUS / 2; //amount to shift  DIR128 stepdir;                //direction of step  INT16 stepindex;               //index to cstep  INT16 farindex;                //index to other side  INT16 halfsteps;               //half of stepcount  halfsteps = (stepcount + 1) / 2;  for (stepindex = 0; stepindex < halfsteps; stepindex++) {    farindex = stepcount - stepindex - 1;    stepdir = step_dir (stepindex);    set_step (stepindex, step_dir (farindex) + halfturn);    set_step (farindex, stepdir + halfturn);  }}/********************************************************************** * C_OUTLINE::move * * Move C_OUTLINE by vector **********************************************************************/void C_OUTLINE::move(                  // reposition OUTLINE                     const ICOORD vec  // by vector                    ) {  C_OUTLINE_IT it(&children);  // iterator  box.move (vec);  start += vec;  for (it.mark_cycle_pt (); !it.cycled_list (); it.forward ())    it.data ()->move (vec);      // move child outlines}/********************************************************************** * C_OUTLINE::plot * * Draw the outline in the given colour. **********************************************************************/#ifndef GRAPHICS_DISABLEDvoid C_OUTLINE::plot(                //draw it                     WINDOW window,  //window to draw in                     COLOUR colour   //colour to draw in                    ) const {  INT16 stepindex;               //index to cstep  ICOORD pos;                    //current position  DIR128 stepdir;                //direction of step  DIR128 oldstepdir;             //previous stepdir  pos = start;                   //current position  line_color_index(window, colour);  move2d (window, pos.x (), pos.y ());  stepindex = 0;  stepdir = step_dir (0);        //get direction  while (stepindex < stepcount) {    do {      pos += step (stepindex);   //step to next      stepindex++;               //count steps      oldstepdir = stepdir;                                 //new direction      stepdir = step_dir (stepindex);    }    while (stepindex < stepcount      && oldstepdir.get_dir () == stepdir.get_dir ());    //merge straight lines    draw2d (window, pos.x (), pos.y ());  }}#endif/********************************************************************** * C_OUTLINE::operator= * * Assignment - deep copy data **********************************************************************/                                 //assignmentC_OUTLINE & C_OUTLINE::operator= (const C_OUTLINE & source         //from this) {  box = source.box;  start = source.start;  if (steps != NULL)    free_mem(steps);  stepcount = source.stepcount;  steps = (UINT8 *) alloc_mem (step_mem());  memmove (steps, source.steps, step_mem());  if (!children.empty ())    children.clear ();  children.deep_copy (&source.children);  return *this;}

⌨️ 快捷键说明

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