Exemple #1
0
        private void DrawStrokePart(StrokePart part, Graphics graphics, Pen pen1, Pen pen2)
        {
            Vector2f topLeft = new Vector2f(10, 10);
            Vector2f scale   = new Vector2f(0.01f, 0.01f);

            if (allStrokes.Count > 0)
            {
                KanjiMatcher.CalcResize(allStrokes, matchedTemplate, out topLeft, out scale);
            }

            graphics.DrawLine(pen1,
                              new PointF(topLeft.X + part.StartPoint.X / scale.X, topLeft.Y + part.StartPoint.Y / scale.Y),
                              new PointF(topLeft.X + part.EndPoint.X / scale.X, topLeft.Y + part.EndPoint.Y / scale.Y));
            const int sections = 64;

            PointF[] roundPoints = new PointF[sections + 1];
            Vector2f delta       = part.EndPoint - part.StartPoint;
            Vector2f ortho       = new Vector2f(delta.Y, -delta.X);

            for (int i = 0; i <= sections; i++)
            {
                float    pos   = (float)i / sections;
                Vector2f point = part.GetGlobalFromProgress(pos);
                float    param = 1 - (2 * pos - 1) * (2 * pos - 1);
                point          = topLeft + new Vector2f(point.X / scale.X, point.Y / scale.Y);
                roundPoints[i] = new PointF(point.X, point.Y);
            }
            graphics.DrawLines(pen2, roundPoints);
        }
 public static float Match(List<List<Vector2f>> input, List<StrokeTemplate> template, out List<StrokeMatch> match)
 {
     match = null;
     if (input.Count != template.Count)
         return float.PositiveInfinity;
     KanjiMatcher matcher = new KanjiMatcher();
     matcher.Input = input.Select(stroke => stroke.ToList()).ToList();//Deep copy input
     matcher.Template = template;
     matcher.Resize();
     matcher.MatchStrokes();
     float cost = matcher.TotalCost();
     match = matcher.BestMatch;
     return cost;
 }
Exemple #3
0
        private void match_Click(object sender, EventArgs e)
        {
            float bestMatchCost = float.PositiveInfinity;

            foreach (var template in templates)
            {
                List <StrokeMatch> match;
                float cost = KanjiMatcher.Match(allStrokes, template, out match);
                if (cost < bestMatchCost)
                {
                    bestMatchCost   = cost;
                    bestMatch       = match;
                    matchedTemplate = template;
                }
            }
            matchQuality.Text = bestMatchCost.ToString();
        }
Exemple #4
0
        public static float Match(List <List <Vector2f> > input, List <StrokeTemplate> template, out List <StrokeMatch> match)
        {
            match = null;
            if (input.Count != template.Count)
            {
                return(float.PositiveInfinity);
            }
            KanjiMatcher matcher = new KanjiMatcher();

            matcher.Input    = input.Select(stroke => stroke.ToList()).ToList();         //Deep copy input
            matcher.Template = template;
            matcher.Resize();
            matcher.MatchStrokes();
            float cost = matcher.TotalCost();

            match = matcher.BestMatch;
            return(cost);
        }