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

📄 oldbasel.cpp

📁 一OCR的相关资料。.希望对研究OCR的朋友有所帮助.
💻 CPP
📖 第 1 页 / 共 5 页
字号:
//      {  if (runlength>bestrun)//            bestrun=runlength;                           /*find biggest run*///         runlength=1;                                    /*new run*///      }//      else//      {  runlength++;//      }//   }//   if (runlength>bestrun)//      bestrun=runlength;////   for (blobindex=0;blobindex<blobcount;blobindex++)//   {  if (blobindex<1//      || partids[blobindex]!=partids[blobindex-1])//      {  if ((blobindex+1>=blobcount//         || partids[blobindex]!=partids[blobindex+1])//                                                         /*loner*///         && (bestrun>2 || partids[blobindex]!=bestpart))//         {  partids[blobindex]=partcount;                /*discard loner*///         }//         else if (blobindex+1<blobcount//         && partids[blobindex]==partids[blobindex+1]//                                                         /*pair*///         && (blobindex+2>=blobcount//         || partids[blobindex]!=partids[blobindex+2])//         && (bestrun>3 || partids[blobindex]!=bestpart))//         {  partids[blobindex]=partcount;                /*discard both*///            partids[blobindex+1]=partcount;//         }//      }//   }//   for (blobindex=0;blobindex<blobcount;blobindex++)//   {  if (partids[blobindex]<partcount)//         partids[blobindex]=0;                           /*all others together*///   }//}/********************************************************************** * partition_coords * * Get the x,y coordinates of all points in the bestpart and put them * in xcoords,ycoords. Return the number of points found. **********************************************************************/intpartition_coords (               //find relevant coordsBOX blobcoords[],                //bounding boxesint blobcount,                   /*no of blobs in row */char partids[],                  /*partition no of each blob */int bestpart,                    /*best new partition */int xcoords[],                   /*points to work on */int ycoords[]                    /*points to work on */) {  register int blobindex;        /*no along text line */  int pointcount;                /*no of points */  pointcount = 0;  for (blobindex = 0; blobindex < blobcount; blobindex++) {    if (partids[blobindex] == bestpart) {                                 /*centre of blob */      xcoords[pointcount] = (blobcoords[blobindex].left () + blobcoords[blobindex].right ()) >> 1;      ycoords[pointcount++] = blobcoords[blobindex].bottom ();    }  }  return pointcount;             /*no of points found */}/********************************************************************** * segment_spline * * Segment the row at midpoints between maxima and minima of the x,y pairs. * The xstarts of the segments are returned and the number found. **********************************************************************/intsegment_spline (                 //make xstartsBOX blobcoords[],                //boundign boxesint blobcount,                   /*no of blobs in row */int xcoords[],                   /*points to work on */int ycoords[],                   /*points to work on */int degree, int pointcount,      /*no of points */int xstarts[]                    //result) {  register int ptindex;          /*no along text line */  register int segment;          /*partition no */  int lastmin, lastmax;          /*possible turn points */  int turnpoints[SPLINESIZE];    /*good turning points */  int turncount;                 /*no of turning points */  int max_x;                     //max specified coord  xstarts[0] = xcoords[0] - 1;   //leftmost defined pt  max_x = xcoords[pointcount - 1] + 1;  if (degree < 2)    pointcount = 0;  turncount = 0;                 /*no turning points yet */  if (pointcount > 3) {    ptindex = 1;    lastmax = lastmin = 0;       /*start with first one */    while (ptindex < pointcount - 1 && turncount < SPLINESIZE - 1) {                                 /*minimum */      if (ycoords[ptindex - 1] > ycoords[ptindex] && ycoords[ptindex] <= ycoords[ptindex + 1]) {        if (ycoords[ptindex] < ycoords[lastmax] - TURNLIMIT) {          if (turncount == 0 || turnpoints[turncount - 1] != lastmax)                                 /*new max point */            turnpoints[turncount++] = lastmax;          lastmin = ptindex;     /*latest minimum */        }        else if (ycoords[ptindex] < ycoords[lastmin]) {          lastmin = ptindex;     /*lower minimum */        }      }                                 /*maximum */      if (ycoords[ptindex - 1] < ycoords[ptindex] && ycoords[ptindex] >= ycoords[ptindex + 1]) {        if (ycoords[ptindex] > ycoords[lastmin] + TURNLIMIT) {          if (turncount == 0 || turnpoints[turncount - 1] != lastmin)                                 /*new min point */            turnpoints[turncount++] = lastmin;          lastmax = ptindex;     /*latest maximum */        }        else if (ycoords[ptindex] > ycoords[lastmax]) {          lastmax = ptindex;     /*higher maximum */        }      }      ptindex++;    }                                 /*possible global min */    if (ycoords[ptindex] < ycoords[lastmax] - TURNLIMIT    && (turncount == 0 || turnpoints[turncount - 1] != lastmax)) {      if (turncount < SPLINESIZE - 1)                                 /*2 more turns */        turnpoints[turncount++] = lastmax;      if (turncount < SPLINESIZE - 1)        turnpoints[turncount++] = ptindex;    }    else if (ycoords[ptindex] > ycoords[lastmin] + TURNLIMIT      /*possible global max */    && (turncount == 0 || turnpoints[turncount - 1] != lastmin)) {      if (turncount < SPLINESIZE - 1)                                 /*2 more turns */        turnpoints[turncount++] = lastmin;      if (turncount < SPLINESIZE - 1)        turnpoints[turncount++] = ptindex;    }    else if (turncount > 0 && turnpoints[turncount - 1] == lastmin    && turncount < SPLINESIZE - 1) {      if (ycoords[ptindex] > ycoords[lastmax])        turnpoints[turncount++] = ptindex;      else        turnpoints[turncount++] = lastmax;    }    else if (turncount > 0 && turnpoints[turncount - 1] == lastmax    && turncount < SPLINESIZE - 1) {      if (ycoords[ptindex] < ycoords[lastmin])        turnpoints[turncount++] = ptindex;      else        turnpoints[turncount++] = lastmin;    }  }  if (textord_oldbl_debug && turncount > 0)    tprintf ("First turn is %d at (%d,%d)\n",      turnpoints[0], xcoords[turnpoints[0]], ycoords[turnpoints[0]]);  for (segment = 1; segment < turncount; segment++) {                                 /*centre y coord */    lastmax = (ycoords[turnpoints[segment - 1]] + ycoords[turnpoints[segment]]) / 2;    /* fix alg so that it works with both rising and falling sections */    if (ycoords[turnpoints[segment - 1]] < ycoords[turnpoints[segment]])                                 /*find rising y centre */      for (ptindex = turnpoints[segment - 1] + 1; ptindex < turnpoints[segment] && ycoords[ptindex + 1] <= lastmax; ptindex++);    else                                 /*find falling y centre */      for (ptindex = turnpoints[segment - 1] + 1; ptindex < turnpoints[segment] && ycoords[ptindex + 1] >= lastmax; ptindex++);                                 /*centre x */    xstarts[segment] = (xcoords[ptindex - 1] + xcoords[ptindex]      + xcoords[turnpoints[segment - 1]]      + xcoords[turnpoints[segment]] + 2) / 4;    /*halfway between turns */    if (textord_oldbl_debug)      tprintf ("Turn %d is %d at (%d,%d), mid pt is %d@%d, final @%d\n",        segment, turnpoints[segment],        xcoords[turnpoints[segment]], ycoords[turnpoints[segment]],        ptindex - 1, xcoords[ptindex - 1], xstarts[segment]);  }  xstarts[segment] = max_x;  return segment;                /*no of splines */}/********************************************************************** * split_stepped_spline * * Re-segment the spline in cases where there is a big step function. * Return TRUE if any were done. **********************************************************************/BOOL8split_stepped_spline (           //make xstartsQSPLINE * baseline,              //current shotfloat jumplimit,                 //max step fuctionint xcoords[],                   /*points to work on */int xstarts[],                   //resultint &segments                    //no of segments) {  BOOL8 doneany;                 //return value  register int segment;          /*partition no */  int startindex, centreindex, endindex;  float leftcoord, rightcoord;  int leftindex, rightindex;  float step;                    //spline step  doneany = FALSE;  startindex = 0;  for (segment = 1; segment < segments - 1; segment++) {    step = baseline->step ((xstarts[segment - 1] + xstarts[segment]) / 2.0,      (xstarts[segment] + xstarts[segment + 1]) / 2.0);    if (step < 0)      step = -step;    if (step > jumplimit) {      while (xcoords[startindex] < xstarts[segment - 1])        startindex++;      centreindex = startindex;      while (xcoords[centreindex] < xstarts[segment])        centreindex++;      endindex = centreindex;      while (xcoords[endindex] < xstarts[segment + 1])        endindex++;      if (segments >= SPLINESIZE) {        if (textord_debug_baselines)          tprintf ("Too many segments to resegment spline!!\n");      }      else if (endindex - startindex >= textord_spline_medianwin * 3) {        while (centreindex - startindex <          textord_spline_medianwin * 3 / 2)          centreindex++;        while (endindex - centreindex <          textord_spline_medianwin * 3 / 2)          centreindex--;        leftindex = (startindex + startindex + centreindex) / 3;        rightindex = (centreindex + endindex + endindex) / 3;        leftcoord =          (xcoords[startindex] * 2 + xcoords[centreindex]) / 3.0;        rightcoord =          (xcoords[centreindex] + xcoords[endindex] * 2) / 3.0;        while (xcoords[leftindex] > leftcoord          && leftindex - startindex > textord_spline_medianwin)          leftindex--;        while (xcoords[leftindex] < leftcoord          && centreindex - leftindex >          textord_spline_medianwin / 2)          leftindex++;        if (xcoords[leftindex] - leftcoord >          leftcoord - xcoords[leftindex - 1])          leftindex--;        while (xcoords[rightindex] > rightcoord          && rightindex - centreindex >          textord_spline_medianwin / 2)          rightindex--;        while (xcoords[rightindex] < rightcoord          && endindex - rightindex > textord_spline_medianwin)          rightindex++;        if (xcoords[rightindex] - rightcoord >          rightcoord - xcoords[rightindex - 1])          rightindex--;        if (textord_debug_baselines)          tprintf ("Splitting spline at %d with step %g at (%d,%d)\n",            xstarts[segment],            baseline->            step ((xstarts[segment - 1] +            xstarts[segment]) / 2.0,            (xstarts[segment] +            xstarts[segment + 1]) / 2.0),            (xcoords[leftindex - 1] + xcoords[leftindex]) / 2,            (xcoords[rightindex - 1] + xcoords[rightindex]) / 2);        insert_spline_point (xstarts, segment,          (xcoords[leftindex - 1] +          xcoords[leftindex]) / 2,          (xcoords[rightindex - 1] +          xcoords[rightindex]) / 2, segments);        doneany = TRUE;      }      else if (textord_debug_baselines) {        tprintf          ("Resegmenting spline failed - insufficient pts (%d,%d,%d,%d)\n",          startindex, centreindex, endindex,          (INT32) textord_spline_medianwin);      }    }    //              else tprintf("Spline step at %d is %g\n",    //                      xstarts[segment],    //                      baseline->step((xstarts[segment-1]+xstarts[segment])/2.0,    //                      (xstarts[segment]+xstarts[segment+1])/2.0));  }  return doneany;}/********************************************************************** * insert_spline_point * * Insert a new spline point and shuffle up the others. **********************************************************************/voidinsert_spline_point (            //get descendersint xstarts[],                   //starts to shuffleint segment,                     //insertion ptint coord1,                      //coords to addint coord2, int &segments        //total segments) {  int index;                     //for shuffling  for (index = segments; index > segment; index--)    xstarts[index + 1] = xstarts[index];  segments++;  xstarts[segment] = coord1;  xstarts[segment + 1] = coord2;}/********************************************************************** * find_lesser_parts * * Average the step from the spline for the other partitions * and find the commonest partition which has a descender. **********************************************************************/voidfind_lesser_parts (              //get descendersTO_ROW * row,                    //row to processBOX blobcoords[],                //bounding boxesint blobcount,                   /*no of blobs */char partids[],                  /*partition of each blob */int partsizes[],                 /*size of each part */int partcount,                   /*no of partitions */int bestpart                     /*biggest partition */) {  register int blobindex;        /*index of blob */

⌨️ 快捷键说明

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