def _scoreStroke(stroke, template, sample_size = None): if sample_size is None: sample_size = len(template) sNorm = GeomUtils.strokeNormalizeSpacing(stroke, len(template)) centr = GeomUtils.centroid(sNorm.Points) numPoints = len(sNorm.Points) point_vect = [] templ_vect = [] numPoints = len(template) if len(template) == len(sNorm.Points): for idx in range(0, numPoints, numPoints/sample_size ): templ_vect.append(template[idx].X) templ_vect.append(template[idx].Y) p = sNorm.Points[idx] point_vect.append(p.X - centr.X) point_vect.append(p.Y - centr.Y) angularDist = GeomUtils.vectorDistance(point_vect, templ_vect) else: angularDist = math.pi return angularDist
def SaveTemplate(self, numSamples = TEMPLATE_SAMPLE): if len(self.StrokeList) > 0: last_stroke = self.StrokeList[-1] template_name = str(len(self.StrokeList)) sNorm = GeomUtils.strokeNormalizeSpacing(last_stroke, numSamples) centroid = GeomUtils.centroid(sNorm.Points) sNorm = sNorm.translate(-1*centroid.X, -1 * centroid.Y) storeTemplate(sNorm, tag=template_name)
def drawMyself( self ): for a in self.annotation_list: center = GeomUtils.centroid(a.Strokes[0].Points) #Ugly hack to get the center of the annotation! templ_stroke = Stroke.Stroke(a.template) templ_stroke = templ_stroke.translate(center.X, center.Y) SketchGUI.drawText(center.X, center.Y, InText=a.name) SketchGUI.drawStroke(templ_stroke, color="#F050F0")
def scoreStroke(stroke, template): sNorm = GeomUtils.strokeNormalizeSpacing(stroke, TEMPLATE_SAMPLE) centr = GeomUtils.centroid(sNorm.Points) point_vect = [] templ_vect = [] for q in template: templ_vect.append(q.X) templ_vect.append(q.Y) for p in sNorm.Points: point_vect.append(p.X - centr.X) point_vect.append(p.Y - centr.Y) angularDist = GeomUtils.vectorDistance(point_vect, templ_vect) return angularDist
def SaveTemplate(self, sender, e, numSamples = TEMPLATE_SAMPLE): if len(self.StrokeList) > 0: #last_stroke = self.StrokeList[-1] pts = [] for stk in self.StrokeList: pts.extend(stk.Points) templ_stroke = Stroke.Stroke(points= pts) template_name = TEMPLATE_TEXT.Text if template_name.strip() == '': template_name = 'Blob' sNorm = GeomUtils.strokeNormalizeSpacing(templ_stroke, numSamples * len(self.StrokeList)) centroid = GeomUtils.centroid(sNorm.Points) sNorm = sNorm.translate(-1*centroid.X, -1 * centroid.Y) storeTemplate(sNorm, len(self.StrokeList), tag=template_name) self.Clear()