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

📄 gw.cc

📁 手写识别是模式识别中研究得一个热点
💻 CC
字号:
#include <SLList.h>#include <stdlib.h>#include "HWRawDataC.hh"void label(HWRawDataC recs[], struct limitsS limits, long Ymin, long Ymax);struct limitsS GetLimits(HWRawDataC recs[], int index, int Ymin);struct limitsS {long upper,lower;};struct limitsS limits;int main(int argc, char *argv[]){  HWHeaderC Header;  cin >> Header;  cout << Header;  SLList<HWDataPointC> Points;  int PenUp = 1, ClassType, index =0,  pendown =0,i;  long Ymin =32000, Ymax=0;  long LastXPos = 0;  HWRawDataC dummy;  dummy.Type = 99;  dummy.Time = 0;  HWRawDataC ThisRecord;  HWRawDataC recs[5000];//  if (argc == 2)//    {small_hgap = atoi(argv[1]);}  HWRawDataC WordBoundRecord, GraphBoundRecord;  WordBoundRecord.Type = 4;  while (ThisRecord.Type != 5)             // stop at EOF record    {      for (i=0; i<5000; i++)	recs[i] = dummy;      Ymin =32000; Ymax = 0; index = 0;      if (!cin) break;      cin >> ThisRecord;      // read records until we get to a pendown event (or EOF)      while ((ThisRecord.Type != PEN_DOWN) &&  // find where word starts	     (ThisRecord.Type != END_OF_FILE))         {cout << ThisRecord;	  cin >> ThisRecord;}      if (ThisRecord.Type == END_OF_FILE) break;      pendown = 1;      // read & store records until we get to the end of the word      while ((ThisRecord.Type != END_WORDBODY) &&  // find where word ends	     (ThisRecord.Type != END_OF_FILE))	{	 // we weren't reading a word frag or word body. Throw info away	 if ((ThisRecord.Type == END_TCROSS) ||	     (ThisRecord.Type == END_IDOT) ||	     (ThisRecord.Type == END_PUNCT) ||	     (ThisRecord.Type == END_TCROSS) ||	     (ThisRecord.Type == END_UNKNOWN) ||	     (ThisRecord.Type == END_STROKEOUT))	   {for (i=0; i<5000; i++)	      {if (recs[i].Type != 99)                  {cout << recs[i];}                recs[i] = dummy;              }	    index=0;	    Ymin=32000; Ymax =0;	  } // end if         // keep record info, update Ymax & Ymin	 if (ThisRecord.Type == PEN_DOWN)            {pendown = 1;}	 if (ThisRecord.Type == PEN_UP)            {pendown = 0;}	 if ((ThisRecord.Type == DATA_RECORD) && (pendown))	   {if (Ymin > ThisRecord.DataPoint.YPos)	      {Ymin = ThisRecord.DataPoint.YPos;}            if (Ymax < ThisRecord.DataPoint.YPos)              {Ymax = ThisRecord.DataPoint.YPos;}	    recs[index++] = ThisRecord;               // put word into array	    } // end if          else            {cout << ThisRecord;}          cin >> ThisRecord;       } //end while      // we have a word so process it      if (ThisRecord.Type != END_OF_FILE)	{limits = GetLimits(recs,index,Ymin);	 label(recs,limits,Ymin,Ymax);         cout << ThisRecord;       }    }}struct limitsS GetLimits(HWRawDataC recs[], int index, int Ymin){  struct limitsS limits;  int ys[1000];  int i=0, sum=0, count =0,j, flag =0;  float savg;  for (i=0; i<1000; i++)    ys[i]=0;  //The place to put each YPos is Ypos - Ymin  for (i=0; i<index; i++)    { if (recs[i].Type == DATA_RECORD)	{ys[recs[i].DataPoint.YPos-Ymin]++;}; //inc the count for that Y coord 	}  for (i=0; i<1000; i++)     // sum the value of all the Y coords     {if (ys[i] !=0)       {sum = ys[i] + sum;      count++;      }   }  savg = (float)sum/(count);  //average value of those Ycoords that have points  //find upper limit  for (i=4; i<1000; i++)    {if ((ys[i]+ys[i-1]+ys[i-2]+ys[i-3]+ys[i-4]) > 2.5*savg)       {limits.upper = i-4 + Ymin;   	break;      }   }  // find lower limit  for (i=999; i>0; i--)    {if ((ys[i]+ys[i-1]+ys[i-2]+ys[i-3]+ys[i-4]) > 3*savg)       {limits.lower = i + Ymin;	break;      }   }  // if lower limit went past upper limit return an error flag  if (limits.lower > limits.upper)    {return limits;}  else    {limits.lower = 0;     return limits;   }}void label(HWRawDataC recs[], struct limitsS limits, long Ymin, long Ymax){  HWRawDataC Rec;  int i, DoAsc=1, DoDes=1;  long AscThresh, DesThresh, MedThresh, LastAscY, LastDesY, LastMedY;  AscThresh =(long) ((Ymin-limits.upper)*0.33+limits.upper);  DesThresh = (long) ((Ymax-limits.lower)*0.33+limits.lower);  MedThresh = (long) ((limits.lower-limits.upper)/2+limits.upper);  LastAscY = LastDesY = MedThresh;  LastMedY = -1;//cout << " Ymin: " << Ymin << " Ymax: " << Ymax << " limits.lower: " << limits.lower << " limits.upper: " << limits.upper << "\n";  if ((limits.upper-Ymin) < (limits.lower-limits.upper)*0.5)    DoAsc = 0;  if ((Ymax - limits.lower) < (limits.lower-limits.upper)*0.5)    DoDes = 0;  for (i=0;i<5000;i++)    {      if (recs[i].Type == 99) break;      //Median Axis      if (LastMedY <= MedThresh && recs[i].DataPoint.YPos > MedThresh)	{	  Rec.Type = MED_DOWN_CROSSING;	  Rec.Time = recs[i].Time;	  cout << Rec;	}      else if (LastMedY > MedThresh && recs[i].DataPoint.YPos <= MedThresh) 	{	  Rec.Type = MED_UP_CROSSING;	  Rec.Time = recs[i].Time;	  cout << Rec;	}      LastMedY = recs[i].DataPoint.YPos;      //Ascenders      if (DoAsc && LastAscY <= AscThresh && recs[i].DataPoint.YPos > AscThresh)	{	  Rec.Type = ASC_DOWN_CROSSING;	  Rec.Time = recs[i].Time;	  cout << Rec;	}      else if (DoAsc && LastAscY > AscThresh && recs[i].DataPoint.YPos <= AscThresh) 	{	  Rec.Type = ASC_UP_CROSSING;	  Rec.Time = recs[i].Time;	  cout << Rec;	}      LastAscY = recs[i].DataPoint.YPos;      //Descenders      if (DoDes && LastDesY <= DesThresh && recs[i].DataPoint.YPos > DesThresh)	{	  Rec.Type = DES_DOWN_CROSSING;	  Rec.Time = recs[i].Time;	  cout << Rec;	}      else if (DoDes && LastDesY > DesThresh && recs[i].DataPoint.YPos <= DesThresh) 	{	  Rec.Type = DES_UP_CROSSING;	  Rec.Time = recs[i].Time;	  cout << Rec;	}      LastDesY = recs[i].DataPoint.YPos;      cout << recs[i];    }  //end for}

⌨️ 快捷键说明

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