def Recognize(self, points, acceptedGesturesNames=None): p = Utils.Resample(points, Value.NumResamplePoints) radians = Utils.AngleInRadians(Utils.Centroid(p), p[0], False) p = Utils.RotateByRadians(p, -radians) p = Utils.ScaleTo(p, Value.ResampleScale) p = Utils.TranslateCentroidTo(p, Value.ResampleOrigin) # # Uncomment these lines to add new gestures (and change Name !) # print '<?xml version="1.0" encoding="utf-8" standalone="yes"?>' # print '<Gesture Name="name" NumPts="%d" Millseconds="%d" AppName="WUW01" AppVer="1.0.0.0" Date="Wenesday, January 08, 2016" TimeOfDay="14:56:51 PM">' % (len(p), points[-1].T - points[0].T); # for k in p: # print ' <Point X="%d" Y="%d" T="%d" />' % (k.X, k.Y, k.T) # print '</Gesture>' nBest = NBestList() for pp in self.__gestures: if acceptedGesturesNames is None or pp.Name in acceptedGesturesNames or pp.Name == "close": best = self.GoldenSectionSearch(p, pp.Points, Utils.DegToRad(-45.0), Utils.DegToRad(+45.0), Utils.DegToRad(2.0)) score = 1.0 - best[0] / Value.HalfDiagonal nBest.AddResult(pp.Name, score, best[0], best[1]) nBest.AddResult("Try Again", Value.tolerance, 0.0, 0.0) nBest.SortDescending() return nBest
def Recognize(self, points): p = Utils.Resample(points, Value.NumResamplePoints) radians = Utils.AngleInRadians(Utils.Centroid(p), p[0], False) p = Utils.RotateByRadians(p, -radians) p = Utils.ScaleTo(p, Value.ResampleScale) p = Utils.TranslateCentroidTo(p, Value.ResampleOrigin) nBest = NBestList() for pp in self.__gestures: best = self.GoldenSectionSearch(p, pp.Points, Utils.DegToRad(-45.0), Utils.DegToRad(+45.0), Utils.DegToRad(2.0)) score = 1.0 - best[0] / Value.HalfDiagonal nBest.AddResult(pp.Name, score, best[0], best[1]) nBest.AddResult("Try Again", Value.tolerance, 0.0, 0.0) nBest.SortDescending() return nBest
def __init__(self, name="", points=[]): self.Name = name self.RawPoints = [] for p in points: self.RawPoints.append(p[:]) if len(points) == 0: self.Points = [] else: p = Utils.Resample(points, Value.NumResamplePoints) radians = Utils.AngleInRadians(Utils.Centroid(p), p[0], False) p = Utils.RotateByRadians(p, -radians) p = Utils.ScaleTo(p, Value.ResampleScale) p = Utils.TranslateCentroidTo(p, Value.ResampleOrigin) self.Points = p