public void logPoints(Shape currentShape, bool success, int curSet, int curSeq, int shapeInd) { // Append new text to an existing file. // The using statement automatically flushes AND CLOSES the stream and calls // IDisposable.Dispose on the stream object. Console.WriteLine("Logging points..."); using (System.IO.StreamWriter file = new System.IO.StreamWriter(fileName, true)) { file.WriteLine("Intended Shape: {0}", currentShape.name); if (success) { file.WriteLine("Success"); } else { file.WriteLine("Failure"); } file.WriteLine(points.Count); for (int i = 0; i < points.Count; i++) { file.WriteLine("{0},{1},{2},{3},{4},{5},{6},{7},{8}", i, points[i].X, points[i].Y, points[i].stroke, points[i].time, points[i].pressure,curSet,curSeq,shapeInd); } } Console.WriteLine("Done logging points."); }
public void ResetPoints(Shape currentShape, bool success, int curSet, int curSeq, int shapeInd) { logPoints(currentShape, success, curSet, curSeq, shapeInd); points.Clear(); }
//Returns the Tanimoto coefficient private double Tanimoto(Shape s) { Trace.WriteLine("Starting Tanimoto"); int gridLen = 10; Trace.WriteLine("Sketch grid:"); List<List<bool>> sketchGrid = CalculateTaniGrid(points, gridLen); double maxScore = 0; for(int i=0;i<s.numTemplates;i++) { Trace.WriteLine("Starting template " + i); List<List<bool>> templateGrid = CalculateTaniGrid(s.templates[i], gridLen); Trace.WriteLine("Finished grid " + i); int union = 0; int sketchTrue = 0; int tempTrue = 0; for(int j=0;j< gridLen;j++) for(int k=0;k< gridLen;k++) { if (sketchGrid[j][k] && templateGrid[j][k]) { union++; Trace.WriteLine("sketchGrid[" + j + "][" + k + "] == templateGrid of same."); } if (sketchGrid[j][k]) sketchTrue++; if (templateGrid[j][k]) tempTrue++; } double score = (double)union / (sketchTrue + tempTrue - union); Trace.WriteLine("Union is " + union); Trace.WriteLine("Bottom is " + (sketchTrue + tempTrue - union)); Trace.WriteLine("Template "+i+" has a score of "+score); if (score > maxScore) maxScore = score; } return maxScore; }
private double PDollar(List<DrawPoint> givenPoints, Shape s) { double score = Double.MaxValue; int n = 32; //Console.WriteLine("norm points"); List<DrawPoint> normPoints = normalize(givenPoints, n); //Console.WriteLine("normPoints has " + normPoints.Count); //Console.WriteLine("attempt template 1"); for (int i=0;i<s.numTemplates;i++) { //Console.WriteLine("norm template "+i); List<DrawPoint> normTemplate = normalize(s.getTemplate(i),n); //Console.WriteLine("normTemplate{0} has {1}",i, normTemplate.Count); //Console.WriteLine("start cloudmatch"); double d = GreedyCloudMatch(normPoints, normTemplate, n); if(score > d) score = d; } return score; }
//Uses the OneDollarRecognizer to analyze the shape private bool OneDollarRecognizer(Shape s) { //Resample //Rotate based on "Indicative Angle" //Scale and translate //Find optimal angle for best score return false; }
//Returns the Hausdorff distance private double Hausdorff(Shape s) { List<DrawPoint> sketchResampled = RescalePoints(ResamplePoints(points,128),40); double bestHaus = Double.MaxValue; for(int i=0;i<s.numTemplates;i++) { List<DrawPoint> tempResampled = RescalePoints(ResamplePoints(points, 128), 40); double thisHaus = Math.Max(OneWayHaus(sketchResampled,tempResampled),OneWayHaus(tempResampled,sketchResampled)); if (thisHaus < bestHaus) bestHaus = thisHaus; } return bestHaus; }
//Classifies the current list of points as either the given shape template or not. public bool TryRecognizeShape(Shape s) { if (points.Count == 0) return false; //bool success = OneDollarRecognizer(s); //Console.WriteLine("attempt $p"); double val = PDollar(points, s); Console.WriteLine("p$ val is "+val); bool success = val < PDollarThreshold; return success; }