Beispiel #1
0
        private void theInkCanvas_StrokeCollected(object sender, InkCanvasStrokeCollectedEventArgs e)
        {
            var stroke = GetCombinedStore(this.theInkCanvas.Strokes);

            InkAnalyzer theInkAnalyzer = new InkAnalyzer();

            //theInkAnalyzer.AddStrokes(this.theInkCanvas.Strokes, 0x0804);
            //theInkAnalyzer.SetStrokesType(this.theInkCanvas.Strokes, StrokeType.Writing);

            theInkAnalyzer.AddStroke(stroke, 0x0804);
            theInkAnalyzer.SetStrokeType(stroke, StrokeType.Writing);
            AnalysisStatus status = theInkAnalyzer.Analyze();

            if (status.Successful)
            {
                List <StrokeWord> slist = new List <StrokeWord>();
                //textBox1.Text = theInkAnalyzer.GetRecognizedString();
                for (int i = 0; i < theInkAnalyzer.GetAlternates().Count; i++)
                {
                    StrokeWord sw = new StrokeWord();
                    sw.StrokeName = theInkAnalyzer.GetAlternates()[i].RecognizedString;
                    slist.Add(sw);
                }

                this.StrokeWordList = new List <StrokeWord>();
                this.StrokeWordList = slist;
            }
            else
            {
                MessageBox.Show("识别失败");
            }
        }
        /// <summary>
        /// 识别
        /// </summary>
        /// <param name="strokes">笔迹集合</param>
        /// <returns>候选词数组</returns>
        public string[] Recognize(StrokeCollection strokes)
        {
            if (strokes == null || strokes.Count == 0)
            {
                return(Params.EmptyAlternates);
            }

            var stroke = GetCombinedStore(strokes);

            var analyzer = new InkAnalyzer();

            analyzer.AddStroke(stroke, Params.SimplifiedChineseLanguageId);
            analyzer.SetStrokeType(stroke, StrokeType.Writing);

            var status = analyzer.Analyze();

            if (status.Successful)
            {
                var result = analyzer.GetAlternates()
                             .OfType <AnalysisAlternate>()
                             .Select(x => x.RecognizedString)
                             .ToArray();
                analyzer.Dispose();
                return(result);
            }

            analyzer.Dispose();

            return(Params.EmptyAlternates);
        }
Beispiel #3
0
        /// <summary>
        /// 识别(将多个笔画集合成一起识别,提高单字的识别率)
        /// </summary>
        /// <param name="strokes">笔迹集合</param>
        /// <returns>候选词数组</returns>
        public string[] Recognize(StrokeCollection strokes)
        {
            if (strokes == null || strokes.Count == 0)
            {
                return(null);
            }

            var stroke = GetCombinedStore(strokes);

            var analyzer = new InkAnalyzer();

            analyzer.AddStroke(stroke, 0x0804);
            analyzer.SetStrokeType(stroke, StrokeType.Writing);

            var status = analyzer.Analyze();

            if (status.Successful)
            {
                return(analyzer.GetAlternates()
                       .OfType <AnalysisAlternate>()
                       .Select(x => x.RecognizedString)
                       .ToArray());
            }

            analyzer.Dispose();

            return(null);
        }