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

📄 velocitydet.cc

📁 手写识别是模式识别中研究得一个热点
💻 CC
字号:
//// VelocityDet - It reads the raw data and inserts markers for the //  minimum and maximum velocity points (only pen down data points are //  processed). Maximum velocity points are those above a relative threshold//  determined by a point MAX_PROPORTION times the average above the average.//  Minimum points are detemined similarly below a relative low threshold//  which is a function of the average and MIN_PROPORTION.// Input - reads HWRawDataC records from standard in.// Output - writes HWRawDataC records to standard out w/velocity events.// Notes - 0,0 is the data point in the upper left of the tablet/screen.//// System Include Files.#include <SLList.h>#include <math.h>#include <stdlib.h>// Local Include Files.#include "HWRawDataC.hh"// Manifest Constants.#define AVG_WINDOW_SIZE 1#define MIN_PROPORTION .8#define MAX_PROPORTION 1.4#define OFFSET END_OF_FILE+1-MAX_VELOCITY // Set this to 0 if  mixed event 					  // streams are desired (otherwise					  // this offset maps markers just					  // above END_OF_FILE for DispHW. // Prototypes.float GetDistanceBetween(HWDataPointC, HWDataPointC);float GetVelocityBetween(HWRawDataC, HWRawDataC); // Global Variablesint main(int argc, char *argv[]){  // Read off the header for later.  HWHeaderC Header;  cin >> Header;  // Put all of the data points in a list for averaging and later processing.  SLList<HWRawDataC> DataList;  HWRawDataC DataRec;  while(!!(cin >> DataRec))    DataList.append(DataRec);  // Process the data to find the average.  SLList<HWRawDataC> AvgList;  int PenDown = 0;  float VelocityTotal = 0;  int VelocityCount = 0;  Pix DataPtr = DataList.first();  while(DataPtr != NULL)    {      DataRec = DataList(DataPtr);      switch(DataRec.Type)	{	case DATA_RECORD:	  // Only process points that are down.	  if (PenDown)	    {	      // Make sure there is a starting point in the list.	      if (AvgList.length() > 1)		{		  // Get the velocity to this point and add it to total.		  float Velocity = GetVelocityBetween(AvgList.rear(), DataRec);		  // cerr << " Velocity = " << Velocity << "\n";		  VelocityTotal += Velocity;		  VelocityCount++;		}	      AvgList.append(DataRec);	    }	  break;	case PEN_DOWN:	  PenDown = 1;	  AvgList.append(DataRec);	  // cerr << "Pen Down\n";	  break;	case PEN_UP:	  PenDown = 0;	  AvgList.clear();	  // cerr << "Pen Up\n";	  break;	default:	  cerr << "Unknown data type " << DataRec.Type << "\n";	  break;	}      DataList.next(DataPtr);    }  cerr << "VelocityTotal = " << VelocityTotal << ", VelocityCount = " <<    VelocityCount << "\n";  // Calculate the realtive maximum and minimum velocity thresholds.  float VelocityAvg = VelocityTotal/VelocityCount;  float MaxThreshold = VelocityAvg * (1+MAX_PROPORTION);  float MinThreshold = VelocityAvg * (1-MIN_PROPORTION);  cerr << "VelocityAvg = " << VelocityAvg << ", MaxThreshold = " <<    MaxThreshold << ", MinThreshold = " << MinThreshold << "\n\n";  // Put the header on the output stream.  cout << Header;  // Process the data to output the min and max velocity markers.  DataPtr = DataList.first();  while(DataPtr != NULL)    {      DataRec = DataList(DataPtr);      // Pass through all of the original data points.      cout << DataRec;      switch(DataRec.Type)	{	case DATA_RECORD:	  // Only process points that are down.	  if (PenDown)	    {	      // Make sure there is a starting point in the list.	      if (AvgList.length() > 1)		{		  // Get the velocity to this point.		  float Velocity = GetVelocityBetween(AvgList.rear(), DataRec);		  cerr << "Time = " << DataRec.Time << " Velocity = " 		    << Velocity << "\n";		  // Set up velocity marker (if needed).		  HWRawDataC VelocityMarker;		  VelocityMarker.Time = DataRec.Time;		  // Check if this velocity is above the max threshold.		  if (Velocity > MaxThreshold)		    {		      // Output the maximum velocity marker.		      VelocityMarker.Type = MAX_VELOCITY+OFFSET;		      cout << VelocityMarker;		    }		  else		    {		      // Check if this velocity is below the min threshold.		      if (Velocity < MinThreshold)			{			  // Output the minimum velocity marker.			  VelocityMarker.Type = MIN_VELOCITY+OFFSET;			  cout << VelocityMarker;						}		    }		}	      AvgList.append(DataRec);	    }	  break;	case PEN_DOWN:	  PenDown = 1;	  AvgList.append(DataRec);	  cerr << "Pen Down\n";	  break;	case PEN_UP:	  PenDown = 0;	  AvgList.clear();	  cerr << "Pen Up\n";	  break;	default:	  cerr << "Unknown data type " << DataRec.Type << "\n";	  break;	}      DataList.next(DataPtr);    }}//// GetDistanceBetween - returns the distance between points A and B.//float GetDistanceBetween(HWDataPointC A, HWDataPointC B){  return(sqrt( pow((double)abs(A.XPos-B.XPos),2) +               pow((double)abs(A.YPos-B.YPos), 2) ));}//// GetVelocityBetween - returns the velocity between to data points based//  on the Time and DataPoint fields.//float GetVelocityBetween(HWRawDataC A, HWRawDataC B){  static float OldVels[AVG_WINDOW_SIZE];  static int NextEntry = 0;  if (B.Time-A.Time != 0)    {      float ThisVel = 	GetDistanceBetween(A.DataPoint,B.DataPoint);//	GetDistanceBetween(A.DataPoint,B.DataPoint)/(B.Time-A.Time);      OldVels[(NextEntry++)%AVG_WINDOW_SIZE] = ThisVel;    }  float Ave=0;  for (int I=0; I<AVG_WINDOW_SIZE;I++) Ave+=OldVels[I];  return Ave/AVG_WINDOW_SIZE;}

⌨️ 快捷键说明

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