def recognize(self, traces): #security verification for trace in traces: if len(trace) < 2: return (None, 0) #return none gesture #information about the gesture numTracesGesture = len(traces) pointsGesture = Helper.normalizeGesture(traces) #comparison process bestDistance = float('infinity') bestTemplate = None for template in self.templates: distance = Helper.distanceAtBestAngle(pointsGesture, numTracesGesture, template, -angleRange, +angleRange, anglePrecision) if distance < bestDistance: bestDistance = distance bestTemplate = template score = 1.0 - (bestDistance / halfDiagonal) #get the best template if bestTemplate == None: return(None, 0) else: return (bestTemplate.name, score)
def __init__(self, name, gesture): self.name = name self.numTracesGesture = len(gesture) self.points = Helper.normalizeGesture(gesture)